Route Fallback: When no Other Route is Matched

If you want to specify additional logic for not-found routes, instead of just throwing default 404 page, you may create a special Route for that, at the very end of your Routes file.

1Route::group(['middleware' => ['auth'], 'prefix' => 'admin', 'as' => 'admin.'], function () {
2 Route::get('/home', 'HomeController@index');
3 Route::resource('tasks', 'Admin\TasksController');
4});
5 
6// Some more routes....
7Route::fallback(function() {
8 return 'Hm, why did you land here somehow?';
9});

Like our articles?

Become a Premium Member for $129/year or $29/month
What else you will get:
  • 22 courses (477 lessons, total 38 h 20 min)
  • 2 long-form tutorials (one new every week)
  • access to project repositories
  • access to private Discord