Home > Software engineering >  Can I change a Laravel error message globally?
Can I change a Laravel error message globally?

Time:01-27

I can do stuff like this in the request.

public function messages() 
{
    return [
        'title.required' => 'A title is required',
        'body.required'  => 'A message is required',
    ];
}

But I still feel like I will repeat a lot of my code, cause in my case, I will also repeat many of the same error messages for different errors and fields. So is there a way to modify the required error, for example, for the scope of the whole project?

CodePudding user response:

You can override the default validation language lines in the resources/lang/[lang]/validation.php file if that's what you mean.

For example, you can find the line:

'required' => 'The :attribute field is required.'

And change it to whatever you'd like it to say.

  • Related