In Laravel how to redirect to 404 page on accessing post route

| By Webner

In Laravel, when a user directly accesses a post route then an exception page is shown. How to show a 404 page instead?

To fix this issue :

Firstly, you need to create an error page in view folder of your project like 404.blade.php and put content in it (sample below):

Lastly, open your route file web.php and add following text to it:

In this, I have used get() to handle the request to post route. Now if anybody attempts to open this URL directly then automatically control transfers to the 404 page.


Leave a Reply

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