Laravel路由冲突问题 [英] Laravel Routing Conflict issue
本文介绍了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
这篇关于Laravel路由冲突问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文