How to organize routing on laravel? For example, when I do this:

Route::get('/{url}', 'Controller@index') 

I easily open links like site.com/url And what if I need to specifically specify the route for example

 Route::get('/page', 'Page@index') 

How to make it so that it does not conflict with the first route? After all, in fact it is the same

  • 2
    swap? - Zippbl4

2 answers 2

Routes are processed from top to bottom, which means you can put a more general route below.

 Route::get('/page', 'Page@index'); Route::get('/{url}', 'Controller@index'); 

And everything will work.

    Try through switch:

     Route::get('/{url}',function ($url){ switch ($url){ case 'post': function (Page $page){ $page->index(); } break; default: function(Controller $controller){ $controller->index(); } } });