我不确定这是好的做法还是坏的做法,但我正在尝试根据用户角色使用不同的控制器/方法加载相同的路由。
尝试像下面这样进行角色过滤,但不确定这是否是正确的方法:
Route::group(['before' => 'role:admin'], function() {
Route::get('/', 'FirstController@index');
});
Route::group(['before' => 'role:editor'], function() {
Route::get('/', 'SecondController@index');
});
Route::filter('role', function($route, $request, $value) {
// what to do here and is this the right way?
});
但是我无法让它起作用。我该如何实现这个目标?
编辑
发现了这个线程:Laravel同一路由,不同控制器 但是被接受的答案:
if( ! Auth::check())
在routes.php中始终返回false。