I am trying to extract a key from an array using a Laravel ( $errors) error dump .
The array is as follows:
ViewErrorBag {
"default" => MessageBag {
"name" => array:1 [▼
0 => "The name field is required."
]
"role_id" => array:1 [▼
0 => "The role id field is required."
]
]
}
]
}
Using a loop @foreachto get an error message is working fine.
@foreach($errors->all() as $error)
<li>{{$error}}</li>
@endforeach
But I want to get nameand role_id. Anyway, to achieve this? So far I have tried using below and some other methods with no luck.
@foreach ($errors->all() as $key => $value)
Key: {{ $key }}
Value: {{ $value }}
@endforeach
source
share