Home / Snippets / How to Define Fallback Routes in Laravel 8
How to Define Fallback Routes in Laravel 8 cover

How to Define Fallback Routes in Laravel 8

947

3 years ago

0 comments

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]);
});
notion avatar

Alaz

Week-end developer currently experimenting with web, mobile, and all things programming.

Topics:

Frontend

Resource

Average

Average

Support Us

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

Welcome to PostSrc V3

PostSrc Dark Logo

You have to login to favorite this