-5

Laravel change validation default message

  • change validation message from front side
  • read validation.php file and than write that file from front side

is it possible ?

Harsh
  • 1
  • 1
  • What do you mean `from front side`? – Tra Lee Oct 14 '21 at 10:13
  • 1
    yes it's possible. But i think it's not a proper question here. – fatm Oct 14 '21 at 10:14
  • 1
    On Stackoverflow we expect you to do proper research before asking a question. right in documentation you have many options to customize validation messages https://laravel.com/docs/8.x/validation – N69S Oct 14 '21 at 10:34

1 Answers1

0

Use Validator class

use Illuminate\Support\Facades\Validator;

$rules = [
    'name' => 'required',
    'email' => 'required|email,
];

$messages = [
    'name.required' => 'The :attribute is required',
    'email.required' => 'The :attribute is required',
    'email.email' => 'The :attribute is not valid',
];

$validator = Validator::make($request->all(), $rules, $messages);

if ($validator->fails()) {
    return Redirect::back()->withErrors($validator)->withInput();
} else {
  `enter code here`
}
Kaushal Patel
  • 259
  • 2
  • 7