【问题标题】:When Validation Exception is thrown?什么时候抛出验证异常?
【发布时间】:2016-04-21 11:28:39
【问题描述】:

我试图了解何时引发验证异常。当我的自定义请求规则方法验证失败时,$e instanceof ValidationException 返回 false,$e instanceof HttpResponseException 返回 true,当我在 HttpResponseException 上 return $e->getResponse 时,它确实返回了所需的字段,因此当我的自定义请求验证失败时它会特别触发。我注意到在 Illuminate\Foundation\Exceptions\Handler 类中,渲染方法有声明 elseif ($e instanceof ValidationException && $e->getResponse()) 但它没有被执行,因为 HttpResponseException 是第一个在规则方法验证失败时触发的。所以我有点困惑。

【问题讨论】:

    标签: php laravel laravel-5.2


    【解决方案1】:

    ValidationException 在 trait ValidatesRequests 中被抛出

    参见 Illuminate / Foundation / Validation / ValidatesRequests.php

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-18
      • 1970-01-01
      相关资源
      最近更新 更多