是否可以为以模式开头的所有类似路线添加过滤器' / admin'没有必要手动添加过滤器数百次?
例如:
Route::get('admin/sometehing','controller1')->before('auth');
Route::get('admin/sometehingelse','controller2')->before('auth');
Route::get('admin/sometehingelse')->before('auth');
Route::get('admin/sometehingelse')->before('auth');
x1000
如果是这样我怎么办呢?
答案 0 :(得分:1)
您可以使用Route::group();
对带有前缀的路线进行分组,并应用适用于所有路线的过滤器。
Route::group(array('prefix'=>'admin', 'before' => 'auth'),function() {
Route::get('sometehing','controller1');
Route::get('sometehingelse','controller2');
....
}
希望这有帮助
答案 1 :(得分:0)
您可以将Route Prefixing用于此目的:
Route::group(array('prefix' => 'admin'), function() {
Route::get('sometehing','controller1')->before('auth');
Route::get('sometehingelse','controller2')->before('auth');
Route::get('sometehingelse')->before('auth');
Route::get('sometehingelse')->before('auth');
}