Laravel makes it easy to return custom error pages for various HTTP status codes. For example, if you wish to customize the error page for 404 HTTP status codes, create a resources/views/errors/404.blade.php. This file will be served on all 404 errors generated by your application.
Extend Laravel’s Exception Handler, Illuminate\Foundation\Exceptions\Handler, and override renderHttpException(Symfony\Component\HttpKernel\Exception\HttpException $e) method with your own.
class Handler extends ExceptionHandler {
// …
protected function renderHttpException(HttpException $e) {
$status = $e->getStatusCode();
if (view()->exists(“errors.{$status}”)) {
return response()->view(“errors.{$status}”, compact(‘e’), $status);
}
else {
return (new SymfonyDisplayer(config(‘app.debug’)))->createResponse($e);
}
}
// …
}
There are 0 comments