'Laravel display validation error

I try use this code:

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

and in view have this: screen

I would like the error to be displayed correctly. exemple The name is required.

In debbuger I can see. How to replace validation.required upon "The name is required" enter image description here



Solution 1:[1]

Ok, I found mistake. I didn't have another language to upload. In file app/config.php replace 'locale' => 'pl' to 'en'

Solution 2:[2]

you need to add validation in controller method like this..

    $request->validate([
        'name' => 'required'
    ]);

then you can show your validation error in view :

   @if ($errors->has('name'))
      <li>{{ $errors->first('name') }}</li>
   @endif

and this should also work ...

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

Solution 3:[3]

Here is a good example of handling errors in laravel

message.blade.php

@if($errors->any())
    <div class="alert alert-danger">
        <p><strong>Opps Something went wrong</strong></p>
        <ul>
        @foreach ($errors->all() as $error)
            <li>{{ $error }}</li>
        @endforeach
        </ul>
    </div>
@endif

@if(session('success'))
    <div class="alert alert-success">{{session('success')}}</div>
@endif

@if(session('error'))
    <div class="alert alert-danger">{{session('error')}}</div>
@endif

In your controller update method for instance,

public function update(Request $request, $id)
    {
        $this->validate($request,[
            'title'=>'required',
            'body'=>'required'
        ]);
       //the above validation is important to get the errors caught 
        $post= Post::find($id);
        $post->title = $request->input('title');
        $post->body = $request->input('body');

        $post->save();

        return redirect('/posts')->with('success','Updated successfully');
    }

if you have a layout file as layout.blade.php NOTE: having the error display in the layout file is advantageous to use the message for all purpose.

...
<div class="container">
    @include('message')
    @yield('content')
</div>
...

Solution 4:[4]

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 grantDEV
Solution 2 Ankit24007
Solution 3 Minilik
Solution 4 zeeshan tariq