Understanding Fallback Route in Laravel with Example

Published on March 16, 2020 24 sec read

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. 🙂

Monthly Newsletter

One email a month, packed with the latest tutorials, delivered straight to your inbox.
We'll never send any spam or promotional emails.

Hey, I'm Md Obydullah. I build open-source projects and write on Laravel, Linux server, modern JavaScript and more on web development.