I want to validate the values of an array of objects in Laravel which I pass through the request from the client side (encoded).
First of all, I decode the values passed through the request then validate to check it is null or not.
This is my code
$request->request->set('shopping_list', array_map(function ($arr) {
return json_decode($arr);
}, $request->shopping));
$validator = Validator::make($request->toArray(), [
'shopping_list' => ['required'],
'shopping_list.*' => ['required'],
'shopping_list.*.store' => ['required'],
'shopping_list.*.item' => ['required'],
'shopping_list.*.quantity' => ['required'],
'shopping_list.*.brand' => ['required'],
'shopping_list.*.size' => ['required'],
]);
if (count($validator->errors()) > 0) {
return Response::json($validator->errors()->first(), 422);
}
Unexpectedly the server is returning no error messages. When I return $request->all() or $request->toArray(), after the validation has been done, I am getting the values as follow
If I return it before the validation takes place, I am getting a response like this
How can I fix this issue and validate the items?


['required', 'string']validation rules?return json_decode($arr, true);, does it work?