Home > Software engineering >  Laravel - redirect to 404 Page for Incorrect URL
Laravel - redirect to 404 Page for Incorrect URL

Time:07-28

valid URL - mysite.net/pricing

Invalid URL - mysite.com/pricingdjdjdj or mysite.com/dfdsjdsjds

how to display or redirect to 404 page for invalid URLs in laravel 8.

CodePudding user response:

Laravel doing this automatically for you. But if you have some route like mysite.net/{pricing} which means user can write anything for price. You can check string in your controller and use abort() method with any error code you want. If you want to use custom design for error pages you can create error folder in resources/views and create your desired blade files with the name of error_code.blade.php.

CodePudding user response:

When you dealt with route like mysite.net/{pricing}, Laravel has method called findOrFail

Ex: $find_pricing = Price::findOrFail($pricing);

  • Related