Display validation message Laravel 5.4

Viewed 7825

I have a validate like this :

TitleRequest.php:

public function rules()
{
    return [
        'title_name_report' => 'required|min:2',
        'develop_code' => 'required',
    ];
}

public function messages()
{
    return [
        'title_name_report.required',
        'title_name_report.min',
        'develop_code.required'
    ];
}

Lang/vi/validation.php.

'title_name_report.required'=>"Please enter, :attribute !",
'title_name_report.min'=>"Min length is :attribute",
'develop_code.required'=>"Please enter :attribute !",

'custom' => [
    'attribute-name' => [
        'rule-name' => 'custom-message',
    ],
],

'attributes' => [],

views/title.blade.php

<input type="text" class="form-control" id="title_name_report" name="title_name_report" 
        value="{{old('title_name_report')}}">
    @if($errors->has('title_name_report'))
        <div class="error-text">
            {{$errors->first('title_name_report')}}
        </div>
    @endif

I have 2 question :

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.

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

Please help me, thank so much !

2 Answers
Related