How to generate custom error page in Laravel

Laravel makes it easy to display custom error pages for various HTTP status codes.

Patrick Wan
2 min readMar 7, 2022

--

For example, if you wish to customize the error page for 404 HTTP status codes, create a resources/views/errors/404.blade.php view template. This view will be rendered on all 404 errors generated by your application. The views within this directory should be named to match the HTTP status code they correspond to. The Symfony\Component\HttpKernel\Exception\HttpException instance raised by the abort function will be passed to the view as an $exception variable:

<h2>{{ $exception->getMessage() }}</h2>

You can also publish the error pages with Artisan command. Once the templates have been published, you can start to customize it.

php artisan vendor:publish --tag=laravel-errors

example 404 page:

--

--

Patrick Wan

My name’s Patrick. I’m a Software Developer, experience in Laravel, Vue Js, React Js, Livewire, Jquery, Codegniter, NPM, GIT. I have 5 years plus experience.