Fallback Route | Redirect Automatically 404 Page In Laravel

Hello Artisan

In this tutorial i am going to show you how we can automatically user to 404 page in laravel if their requested content is not fount. In this tutorial we will see how to redirect 404 page in laravel using laravel fallback route. Do you know what is fallback route?

Using the the fallback route Route::fallback method, you may define a route that will be executed when no other route matches the incoming request. Generally, unhandled requests will automatically render a "404" page via your application's exception handler. 

 

Route::fallback(function () {

    return view("404");

});

 

Using this route in your application when unhandled requests will be happend, the user will automatically redirected to 404 page. You don't do anything more than yet. Just paste this code in your web.php file.

 

Note : The fallback route should always be the last route registered by your application.

 

Now you have to just create a custom 404.blade.php file in your views directory. Hope this laravel fallback route tutorial will help you to learm something.