Reputation: 77
I am getting an HTTP request in my controller like this:
try {
$cards = $client = Http::acceptJson()->get('www.my.local', $request->input());
$response = $client->json();
if ($client->clientError()) {
throw new HttpException(400, $error['errors'][0]['detail'] ?? 'Server busy');
}
return view('card::cards.index')
->with([
'items' => $cards['data'],
'meta' => $cards['meta'],
]);
} catch (\Exception $exception) {
return back()->withErrors($exception->getMessage())->withInput();
}
The error response:
[
"error" => "validate error",
"fields" => [
"id" => "init",
......
]
]
And somethings like this:
[
"error" => "server error"
]
I want to show all of the errors array in my blade but I can't.
Upvotes: 0
Views: 817
Reputation: 4271
You can get errors in blade file and showing them using $errors
variable which is available in your blade. More info in laravel doc
@if($errors->any())
<ul>
@foreach($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
@endif
Upvotes: 1