If no route matched route::fallback in laravel

Updated at 21-Sep-2021, By samar

If no route matched route::fallback in laravel

In this article, we will see how to solve "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
  • 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