If no route matched route::fallback in laravel

Sometimes users request a web url or hit an API route which does not exist in our web route list then it returns a 404 error page. The route::fallback method helps you to return the message if web route does not exists in web.php or api.php

Answers 1
  • Return message if no route matched in laravel using Route::fallback

    Route::fallback(function() {
        return 'Route does not exist !';

    Use this code snippet at the bottom of routes\api.php and routes\web.php file to return the message on hit API request or web url in laravel.

  • Back to code snippet queries related laravel