Laravel路由冲突问题

问题描述:

我在laravel中有以下网址:

I have following url in laravel:

1.需要更改自:

localhost/laravel/page/2/

localhost/laravel/2/

我的Route.php是

My Route.php is

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

但是当我更改为

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

我注意到它与其他路线存在冲突问题 ,请帮我

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

先感谢

只需在所有其他路由的最后声明新路由,并添加一个where子句即可,例如,尝试如下操作:

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']
);

您可以选择添加where子句,如下所示:

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