Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Customize Laravel FormRequest autorize method validation

Laravel allows us to authorize, or not, a FormRequest to be processed via the authorize method. If the request isn't authorized, it will throw a \Illuminate\Auth\Access\AuthorizationException exception, with a message:

This action is unauthorized.

Is there somehow to customize this message?

See that I want to customize the message itself. Customizing the error messages of attributes I know it is possible!

like image 921
Gabriel Caruso Avatar asked Sep 09 '17 15:09

Gabriel Caruso


1 Answers

To change the message you can add the following to your FormRequest class.

protected function failedAuthorization()
{
    throw new AuthorizationException('Your new message goes here.');
}
like image 167
Rwd Avatar answered Nov 12 '22 15:11

Rwd