douwei7976
2017-09-09 15:22
浏览 136
已采纳

自定义Laravel FormRequest自动调整方法验证

Laravel allow us to authorize, or not, a FormRequest to be processed via the authorize method. If the request isn't authorized, it will through 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!

图片转代码服务由CSDN问答提供 功能建议

Laravel允许我们授权或不通过授权方法。 如果请求未被授权,它将通过 \ Illuminate \ Auth \ Access \ AuthorizationException 异常,并带有消息:

这 动作是未经授权的。

是否有某种方式可以自定义此消息?

请参阅我要自定义消息本身。 自定义属性的错误消息我知道这是可能的!

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • doushi1957 2017-09-10 08:29
    已采纳

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

    protected function failedAuthorization()
    {
        throw new AuthorizationException('Your new message goes here.');
    }
    

    Hope this helps!

    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • dongtang9855 2017-09-09 15:46

    if you are trying to customise the message authourization exceptional message then use throw new exception in authorization controller itself in else part

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题