Pankaj
Pankaj

Reputation: 10105

Customized validation Message : Laravel 5.2.15

I have the following code written in Request class under Rules method.

public function rules()
{
    return [
        'Currency' => 'required|max:5|min:2|composite_unique:tblcurrency,CurrencyCode',
        'CurrencyCode' => 'required|max:5|min:1',
    ];
}

This works fine. Only issue is, when the validation fails, I get the following message..

validation.composite_unique

What i tried so far?

After writing the below code, still I am getting the same error string.

public function messages () {
    return [
        'validation.composite_unique'  => 'Duplicate Country and code combination found.',
    ];
}

Question: Can we customize the Validation message to make it look more user friendly?

Upvotes: 2

Views: 78

Answers (2)

utsav
utsav

Reputation: 622

public function messages () {
    return [
        'Currency.composite_unique'  => 'Duplicate Country and code combination found.',
    ];
}

Upvotes: 3

Pankaj
Pankaj

Reputation: 10105

I got it worked. Below is the correct way to customize the message.

public function messages () {
    return [
        'composite_unique'  => 'Duplicate Country and code combination found.',
    ];
}

Upvotes: 1

Related Questions