Can authorize method in Request class return customized message for HandlesAuthorization trait?
I believe you shouldn't look at HandlesAuthorization
trait. All you need to do is implementing failedAuthorization
method in your request class.
In FormRequest
class it's defined like this:
/**
* Handle a failed authorization attempt.
*
* @return void
*
* @throws \Illuminate\Auth\Access\AuthorizationException
*/
protected function failedAuthorization()
{
throw new AuthorizationException('This action is unauthorized.');
}
so all you need is to override this method in your UpdateRoleRequest
class for example like this:
protected function failedAuthorization()
{
throw new \Illuminate\Auth\Access\AuthorizationException('User has to be an admin.');
}