custom validation message laravel code example
Example 1: laravel validator make custom message
$rules = [
'name' => 'required',
'email' => 'required|email',
'message' => 'required|max:250',
];
$customMessages = [
'required' => 'The :attribute field is required.'
];
$this->validate($request, $rules, $customMessages);
Example 2: laravel custom validation message
$rules = [
'name' => 'required',
'email' => 'required|email',
'message' => 'required|max:250',
];
$customMessages = [
'required' => 'The :attribute field is required.'
];
$this->validate($request, $rules, $customMessages);
Example 3: laravel validation custom message example
$rules = [
'name' => 'required',
'email' => 'required|email',
'message' => 'required|max:250',
];
$customMessages = [
'required' => 'The :attribute field is required.'
];
$this->validate($request, $rules, $customMessages);
Example 4: how to change validation message in laravel
$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);