0

我是新来的laravel。我正在使用委托角色和权限,这工作正常,但现在我需要添加像管理员这样的每个角色都有他自己的controllerview. 超级管理员应该有自己的控制器和视图。

谁能帮帮我吗?如何访问基于权限controllerview使用委托。

这就是我尝试的方式:

    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']]);
4

1 回答 1

0

你应该在你的 routes.php 中使用 Entrust 中间件。在“superadmin”中间件中添加“superadmin”路由,在“admin”中间件中添加“admin”路由等,并在所有这些之后放置“else”案例。

Route::group(['middleware' => ['role:superadmin']], function() {
    Route::get('/someroute', function(){
        return View::make('superadmin');
    });
});

Route::group(['middleware' => ['role:admin']], function() {
    Route::get('/someroute', function(){
        return View::make('admin');
    });
});

Route::get('/someroute', function(){
    Auth::logout();
        return Redirect::to('/login')
            ->with('flash_notice', 'You don\'t have access!');
});
于 2016-08-25T19:22:42.753 回答