If no route matched route::fallback in laravel

Created 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

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Buy Me A Coffee

Don't forget to share this article! Help us spread the word by clicking the share button below.

We appreciate your support and are committed to providing you valuable and informative content.

We are thankful for your never ending support.