想检查说我有以下路线
Route::group(['middleware' => 'auth'], function(){
Route::get('/{profile_url?}', array('as' => 'profile', 'uses' => 'ProfileController@getProfile'));
Route::get('/settings/password', array('as' => 'chgPassword', 'uses' => 'ProfileController@updatePassword'));
Route::post('/settings/password', array('as' => 'postChgPassword', 'uses' => 'ProfileController@postUpdatePassword'));
Route::get('/settings/email/request', array('as' => 'chgEmailRequest', 'uses' => 'ProfileController@updateEmailRequest'));
Route::post('/settings/email/request', array('as' => 'postChgEmailRequest', 'uses' => 'ProfileController@postUpdateEmailRequest'));
Route::get('/logout', array('as' => 'logout', 'uses' => 'ProfileController@logout'));
});
请注意,我的第一个路由接受一个可选参数,该参数然后将用户路由到一个工作正常的特定配置文件,但是当我有其他路由说/logout
时,laravel路由器也将使用{{ 1}}路由而不是预期的注销路由。有没有什么方法可以指定像
/{profile_url?}
这样的事情?何有人可以用这个问题来启发我。
答案 0 :(得分:2)
因为你首先放置了一个通配符{profile_url?}
,所以Laravel会忽略其余的。因此在使用通配符路由时要小心。你应该把最不具体的路线放在最后一个地方,Lavarel会检查所有特定的路线。如果不匹配,它将转到通配符路由。例如:
Route::group(['middleware' => 'auth'], function(){
Route::get('/{profile_url?}',...); // Lavarel do this
Route::get('/logout',...); // ignore this
});
Route::group(['middleware' => 'auth'], function(){
Route::get('/logout',...); // do this if it matches
Route::get('/{profile_url?}',...); // else do this
});