Laravel 允许我们授权或不授权通过 authorize method 处理 FormRequest。如果请求未经授权,它将通过 \Illuminate\Auth\Access\AuthorizationException
异常,并显示一条消息:
This action is unauthorized.
有没有办法自定义这条消息?
看到我想自定义消息本身。 Customizing the error messages of attributes 我知道这是可能的!
最佳答案
要更改消息,您可以将以下内容添加到 FormRequest
类中。
protected function failedAuthorization()
{
throw new AuthorizationException('Your new message goes here.');
}
关于php - 自定义 Laravel FormRequest autorize 方法验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46132156/