I am trying to retrieve a key from an array using Laravel error dump ($errors).
The array looks like this
ViewErrorBag {#169 ▼
#bags: array:1 [▼
"default" => MessageBag {#170 ▼
#messages: array:2 [▼
"name" => array:1 [▼
0 => "The name field is required."
]
"role_id" => array:1 [▼
0 => "The role id field is required."
]
]
#format: ":message"
}
]
}
Using @foreach loop to get the error message works fine.
@foreach($errors->all() as $error)
<li>{{$error}}</li>
@endforeach
But I want to get that name and role_id. Is there anyway to achieve that? Thus far i have tried the below and some other methods with no luck.
@foreach ($errors->all() as $key => $value)
Key: {{ $key }}
Value: {{ $value }}
@endforeach