Custom Error Pages in Laravel

Tram Ho

Default in Laravel when we give error codes like 404, 401, 500… the system will process and give default error message pages which look very simple and not very nice Today I will show you how you how to customize these pages and this is very simple in version Laravel 8 Because it is a demo, I only create simple pages, the rest you guys can create as you like.

Create project

I will create a demo project using composer

Wait a moment the latest version of laravel 8 will be downloaded to your directory. Next start the project server:

And open the local url: http://127.0.0.1:8000/

Create erors page views

Next we will create views for the pages that will display the corresponding error in the directory resources/views/errors

404.blade.php:

401.blade.php:

500.blade.php:

Similarly for other error codes we also create corresponding views for it. Above we have extended errors.layouts so we will need to create one more layouts.blade file in resources/views/errors

layouts.blade.php:

Check it out Finally to see these views let’s try to edit the routes/web.php file as follows: You can include these error pages in the project depending on each specific router or each specific case, here I put the page right in the home page to test it

and as a result we will get a more vivid error message page

Similar to check other error pages abort(401);, abort(500);… Thanks for watching.

References at : https://welcm.uk/blog/custom-error-pages-in-laravel

Share the news now