1

I want to display my errors in Laravel blade template. How should i go about it?

return view('edit', [
    "id"      => $request->id,
    "data"    => $data,
    "errors"  => $validator->messages(),
    "success" => null,
]);

Expected output is

The mahajan first name may only contain letters.

But This is displayed if i print $errors.

{
  "mahajan_first_name":["The mahajan first name may only contain letters."],
  "mahajan_middle_name":["The mahajan middle name may only contain letters."],
  "mahajan_last_name":["The mahajan last name may only contain letters."]
}
SuperStar518
  • 2,814
  • 2
  • 20
  • 35
Rhugveda Desai
  • 74
  • 2
  • 11
  • I would suggest having a look at the documentation: https://laravel.com/docs/5.8/validation#working-with-error-messages – Rwd May 06 '19 at 07:17

1 Answers1

5

You can print them in an unordered list like this:

@foreach ($errors->all() as $error)
   <li>{{ $error }}</li>
@endforeach

A single error is shown like this:

{{ $errors->first('mahajan_first_name') }}

To check if an error exists you can do:

@if($errors->has('mahajan_first_name'))
 // your code here
@endif
nakov
  • 13,938
  • 12
  • 60
  • 110