dimanche 27 décembre 2015

How to validate Angular object in Laravel form request?

When I submit list of objects with angular, I get in Laravel something like this:

array:2 [ 0 => array:13 [ "id" => 3 "name" => "test"
"admin_id" => 1 "created_at" => "2015-12-27 17:47:38"
"updated_at" => "2015-12-27 17:47:38" "project_id" => 1
"description" => "1231323123" "finished" => 0 "start_date" => "2016-01-01 00:00:00" "end_date" => "2016-01-06 00:00:00"
"depencies" => array:1 [ 0 => array:13 [ "id" => 2
"name" => "TEST123321" "admin_id" => 1 "created_at" => "2015-12-27 17:38:27" "updated_at" => "2015-12-27 17:38:27"
"project_id" => 1 "description" => "TEST123" "finished" => 0 "start_date" => "2015-12-30 00:00:00" "end_date" => "2016-01-01 00:00:00" "depencies" => array:1 [ 0 => array:12 [ "id" => 1 "name" => "test123321"
"admin_id" => 1 "created_at" => "2015-12-27 17:37:41"
"updated_at" => "2015-12-27 17:37:41" "project_id" => 1
"description" => "asdasdas" "finished" => 0
"start_date" => "2015-12-27 00:00:00" "end_date" => "2015-12-30 00:00:00" "depencies" => null
"task_expire" => 3 ] ] "depencie_expire" => 2
"task_expire" => 5 ] ] "depencie_expire" => 4
"task_expire" => 10 ] 1 => array:13 [ "id" => 4 "name" => "test123312" "admin_id" => 1 "created_at" => "2015-12-27 17:49:05" "updated_at" => "2015-12-27 17:49:05" "project_id" => 1 "description" => "asdasdas" "finished" => 0 "start_date" => "2016-01-01 00:00:00" "end_date" => "2016-02-10 00:00:00"
"depencies" => array:1 [ 0 => array:13 [ "id" => 2
"name" => "TEST123321" "admin_id" => 1 "created_at" => "2015-12-27 17:38:27" "updated_at" => "2015-12-27 17:38:27"
"project_id" => 1 "description" => "TEST123" "finished" => 0 "start_date" => "2015-12-30 00:00:00" "end_date" => "2016-01-01 00:00:00" "depencies" => array:1 [ 0 => array:12 [ "id" => 1 "name" => "test123321"
"admin_id" => 1 "created_at" => "2015-12-27 17:37:41"
"updated_at" => "2015-12-27 17:37:41" "project_id" => 1
"description" => "asdasdas" "finished" => 0
"start_date" => "2015-12-27 00:00:00" "end_date" => "2015-12-30 00:00:00" "depencies" => null
"task_expire" => 3 ] ] "depencie_expire" => 2
"task_expire" => 5 ] ] "depencie_expire" => 4
"task_expire" => 45 ]]

it above is result from $this->request->get('depencies')

My goal is to be able to validete depencies list items like this:

foreach ($this->request->get('depencies') as $key => $val) {
   $rules['users.' . $key] = "required";
}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire