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

CEO & Founder (BdBooking.com - Online Hotel Booking System), CEO & Founder (TaskGum.com - Task Managment Software), CEO & Founder (InnKeyPro.com - Hotel ERP), Software Engineer & Solution Architect

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

If you recently deployed you project to your produ...

Read more

Laravel Error Fix: Please provide a valid cache path

create these folders under storage/framework: sess...

Read more

Simple Steps to Remove Public in URL (Laravel 5)

1. Rename the server.php in the your Laravel root ...

Read more

There are 0 comments

Leave a Reply

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