Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fields validation default message change in Laravel 5.4

I am using this code for validating a field.

$this->validate($request, [
    'recovery_code' => 'required|exists:users,email_recovery_code',
    'new_password'=>'required',
    'confirm_password'=>'required|same:new_password',
    ]);

and when I enter wrong recovery code i get response

"The selected recovery code is invalid"        

but in place of that I want my custom message. Does anyone know how to do it?

like image 573
nerdyDev Avatar asked Jan 29 '23 21:01

nerdyDev


1 Answers

Its simple, Just do as like this:

$messages = [
        'exists' => 'Your custom message',
    ];
    $this->validate($request, [
    'recovery_code' => 'required|exists:users,email_recovery_code',
    'new_password'=>'required',
    'confirm_password'=>'required|same:new_password',
    ],$messages);

You can set multiple checks on same field in laravel. Just pass them in an array with different key. e.g: exists, required, etc.

Hope it helps you.

Cheers :)

like image 170
Talentelgia Technologies Avatar answered Jan 31 '23 11:01

Talentelgia Technologies