VladWeb developer
Wordpress, Laravel, Yii, REST API, Mobile Development

butterfly

How to create a 404 page in Laravel


Creating a 404 page is not difficult, but it can be difficult to make it work “correctly”.

Many sites describe this process:
- «create a view /resources/views/errors/404».
- «then you edit the render function in the /app/Exceptions/Handler.php file so that it somehow handles the 404 error» - you don’t need to do this!
- then check what happened: open http://my-site/unknown-page and instead of 404 pages something else opens …

Options where a problem could arise:

1. If the page displays the page of the site, for example, the main page, then you need to check /routes/web.php. Most likely, one of the routes processes the "unknown-page" page and any arbitrary page.
2. The error "500 | Server Error »
- in this case, you should first see the error code: in the .env file, set the APP_DEBUG directive to true, then refresh the page, and when you see the php error, fix it.

If the site has no errors or routing problems, then the presence of the file /resources/views/errors/404 is quite enough to display 404 page.