讨论数量:
User::findOrFail(999999);
if ($exception instanceof \Illuminate\Database\Eloquent\ModelNotFoundException) {
dd($exception);
}
我的代码不是7.x 不过应该都一样的吧,表面上看不出你代码有啥毛病,以下是源码。
vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php
/**
* Prepare exception for rendering.
*
* @param \Exception $e
* @return \Exception
*/
protected function prepareException(Exception $e)
{
if ($e instanceof ModelNotFoundException) {
$e = new NotFoundHttpException($e->getMessage(), $e);
} elseif ($e instanceof AuthorizationException) {
$e = new AccessDeniedHttpException($e->getMessage(), $e);
} elseif ($e instanceof TokenMismatchException) {
$e = new HttpException(419, $e->getMessage(), $e);
}
return $e;
}
推荐文章: