Understanding Fallback Route in Laravel with Example

Published: Mar 15, 2020 - Updated: Feb 04, 2023

Using the Route::fallback method, we may define a route that will be executed when no other route matches the incoming request. We need to add the fallback route at the end of all routes.

Fallback route overrides the default 404 page. We’re able to add more custom functionalities too.


The structure of the fallback route is:

Route::fallback(function () {
    // your logic here


Let’s see an example:

// your other routes

// fallback route
Route::fallback(function() {
    return "You're message goes here!";

Now if user enters random URL like https://example.com/hstuwks, the user will see the fallback route’s response.

For this example, the user will see:

You're message goes here!

That’s all. Thank you.


No comments yet…