Elegant code to convert Laravel $validation->messages() to array of objects Elegant code to convert Laravel $validation->messages() to array of objects laravel laravel

Elegant code to convert Laravel $validation->messages() to array of objects


$validation->messages()->all();


Ok, something like this

$response = []; foreach ($validator->messages()->toArray() as $key => $value) {     $obj = new \stdClass();     $obj->name = $key;     $obj->message = $value[0];    array_push($response, $obj); }

It is not elegant but I do not see another way :)