Laravel Routing Conflict issue

人走茶凉 提交于 2019-12-02 16:29:18

问题


I have following url in laravel:

1.Need to change From:

localhost/laravel/page/2/

to

localhost/laravel/2/

My Route.php is

Route::get('page/{id}/',
          array(
        'as'   => 'page', 'uses' =>'Frontcontroller@page'));

But When I change to this,

Route::get('/{id}/',
          array(
        'as'   => 'page', 'uses' =>'Frontcontroller@page'));

I have noticed that it has conflict issues with other route ,Plz help me

Thanx in advance


回答1:


Just declare the new routes at the last of your all other routes and also add a where clause, for example, try something like this:

//All other routes ...

Route::get(
    '/{id}',
    ['as' => 'page', 'uses' =>'Frontcontroller@page']
);

Optionally you may add a where clause like this:

Route::get(
    '/{id}',
    ['as' => 'page', 'uses' =>'Frontcontroller@page']
)
->where('id', '[0-9]+'); // for id as integer


来源:https://stackoverflow.com/questions/31308714/laravel-routing-conflict-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!