Posts Learn Components Snippets Categories Tags Tools About
/

How to Define Fallback Routes in Laravel 8

Learn how to define fallback routes in Laravel and provide a user with a better page when no route matches the incoming request.

Created on Jun 30, 2021

929 views

In Laravel, you can make use of "Route::fallback" method to catch any incoming request that matches no route. Since typically any unhandled requests will automatically render the "404" page, having a fallback route inside the routes/web.php allow you to customize and return a custom route.

You can define the fallback route like below. The content of the view is up to your customization.
#routes/web.php

Route::fallback(function () {
  $message = 'You have hit a fallback page!';

  return view('page.fallback-page', ['message' => $message]);
});

If you like our tutorial, do make sure to support us by being our Patreon or buy us some coffee ☕️

Load comments for How to Define Fallback Routes in Laravel 8

)