Laravel 5 使用预留路由关键字的高级路由
Laravel 5 advance routing with reserved route keywords
想检查说我有以下路线
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 路由器还将使用 /{profile_url?}
路由而不是预期的注销路由。有什么方法可以指定像
这样的保留关键字
Route::get('/{profile_url?}', array('as' => 'profile', 'uses' => 'ProfileController@getProfile')
->except('settings', 'logout'));
类似的东西?呵呵,有人可以用这个问题启发我。
因为您将通配符 {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
});
想检查说我有以下路线
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 路由器还将使用 /{profile_url?}
路由而不是预期的注销路由。有什么方法可以指定像
Route::get('/{profile_url?}', array('as' => 'profile', 'uses' => 'ProfileController@getProfile')
->except('settings', 'logout'));
类似的东西?呵呵,有人可以用这个问题启发我。
因为您将通配符 {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
});