我是laravel
中的新用户。我正在使用托管角色和权限,但工作正常,但现在我需要添加管理员拥有自己的controller
和view
等所有角色。 Superadmin应该拥有自己的控制器和视图。
任何人都可以帮助我吗?
如何使用委托来访问基于controller
和view
的权限。
这是我尝试的方式:
Route::group(['middleware' => ['auth']], function() {
if(Entrust::hasRole('superadmin')) {
return View::make('superadmin');
}
else if(Entrust::hasRole('Admin')) {
return View::make('admin');
}
else {
Auth::logout();
return Redirect::to('/login')
->with('flash_notice', 'You don\'t have access!');
}
Route::get('/home', 'HomeController@index');
Route::resource('users','UserController');
Route::get('roles',['as'=>'roles.index','uses'=>'RoleController@index','middleware' => ['permission:role-list|role-create|role-edit|role-delete']]);
Route::get('roles/create',['as'=>'roles.create','uses'=>'RoleController@create','middleware' => ['permission:role-create']]);
Route::post('roles/create',['as'=>'roles.store','uses'=>'RoleController@store','middleware' => ['permission:role-create']]);
Route::get('roles/{id}',['as'=>'roles.show','uses'=>'RoleController@show']);
Route::get('roles/{id}/edit',['as'=>'roles.edit','uses'=>'RoleController@edit','middleware' => ['permission:role-edit']]);
Route::patch('roles/{id}',['as'=>'roles.update','uses'=>'RoleController@update','middleware' => ['permission:role-edit']]);
Route::delete('roles/{id}',['as'=>'roles.destroy','uses'=>'RoleController@destroy','middleware' => ['permission:role-delete']]);
答案 0 :(得分:0)
你应该在routes.php中使用Entrust中间件。在“superadmin”中间件中添加“superadmin”路由,在“admin”中间件中添加“admin”路由等,并在所有这些之后添加“else”案例。
Left