您一定要确保在通配符之前定义静态路由,否则路由器会将静态路由误认为wilcard。下面有一个简单的例子:
//This will work
Route::get('foo', ' [email protected]');
Route::get('{bar}', '[email protected]');
//In this order, foo will never get called
Route::get('{bar}', '[email protected]');
Route::get('foo', ' [email protected]');
当你开始增加更多的细分到您的路径,你总是希望保持通配符在各自的子组的后面。这就是如何逐步增加路线树。
//This is good
Route::get('foo', ' [email protected]');
Route::get('foo/bar', ' [email protected]');
Route::get('foo/{id}', '[email protected]');
Route::get('foo/bar/stuff', '[email protected]');
Route::get('foo/bar/{id}', '[email protected]');
Route::get('foo/{bar}/stuff', '[email protected]');
Route::get('foo/{bar}/{id}', '[email protected]');
特别是对于你的情况,你会希望有你的路由组织这样开始:
Route::get('/addClickBanner/{id_banner}','[email protected]');
Route::get('someStaticString/{main_category}/{slug}','[email protected]')->where('main_category', '^(?!SomeStaticString$).*');
您的意思是' - >在哪里( 'main_category',“^(?!addClickBanner $ )。*');'?如果'id_banner'是一个数字,而'slug'不是,你可以用'[0-9] +' –
'来限制'id_banner'只使用路由参数,比如在Route :: get('/ {main_category}/{slug}'...)将抓取每一个uri,如果在这条路线之前没有明确指出uri。 – Birdman
你应该在每条你关心的路线下放一条类似'/ {main_category}/{slug}'的路线。像SomeStaticString这样的新路线应放置在这条路线上方。 –