如果要自定义当laravel捕获“未找到”异常时返回的路由,可以使用respondWithRoute()方法更新异常处理程序,如示例13-43所示。
// App\Exceptions\Handler public function render($request, Exception $exception) { if ($exception instanceof ModelNotFoundException && $request->isJson()) { return Route::respondWithRoute('api.fallback.404'); } return parent::render($request, $exception); }
Last updated 5 years ago
Was this helpful?