Display validation message Laravel 5.4 Display validation message Laravel 5.4 laravel laravel

Display validation message Laravel 5.4


You can show all validation errors with this :

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

Put custom validation messages in resources/lang/xx/validation.php file in this format :

'custom' => [    'email' => [        'required' => 'We need to know your e-mail address!',    ],],

More Info : https://laravel.com/docs/5.4/validation#custom-error-messages


  1. How can I display exactly errors message, I have 2 rules but it always display the first rule's message. When I try enter 1 character it still display required message.

Laravel will only validate your input in order. It will not return an error message of the next rules until it didn't pass the first one.

  1. How can I use the langs file so I dont need put message into request files.

You can find to localization details here. It is under

/resources/lang/en/validation.php

If you want to change the validation message tru Request file, You should do it like this

public function messages(){    return [        'title_name_report.required' => "Title is required.",        'title_name_report.min'  => "Title should not less than 2.",        'develop_code.required'  => "Code is required.",    ];}