Laravel 5
Custom HTTP Error Pages in Laravel
November 17, 2016
0

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);
}
}

// …

}

About author

ZERIN

Laravel Error Fix: Laravel 5 InvalidArgumentException in FileViewFinder.php line 137: View [.admin] not found

Laravel makes it easy to return custom error pages...

Read more

Laravel Error Fix: Please provide a valid cache path

Laravel makes it easy to return custom error pages...

Read more

Simple Steps to Remove Public in URL (Laravel 5)

Laravel makes it easy to return custom error pages...

Read more

There are 0 comments

Leave a Reply

Your email address will not be published. Required fields are marked *