Laravel 5.2 and Entrust

2

I have a problem that I have not been able to solve and it has been several hours in the. I am using Laravel 5.2 and the component to manage Roles and Permissions Entrust . Everything is well configured, including the middleware provided by Entrust

'role' => \Zizaco\Entrust\Middleware\EntrustRole::class,
'permission' => \Zizaco\Entrust\Middleware\EntrustPermission::class,
'ability' => \Zizaco\Entrust\Middleware\EntrustAbility::class,

Now, I'm trying to configure my routes and I do it this way:

Route::group(['middleware' => ['role:admin']], function() {
     //MIS RUTAS
});

Up there all right, when I enter with admin I have access to everything and when I enter the BASIC ROLE I am limited, until there is still good, but there is a "SPECIAL" profile that has access to everything, except a route, Then I do the following:

Route::group(['middleware' => ['role:admin|especial']], function() {
     //MIS RUTAS
});

When I do this, when I log in with a role user "admin" everything works fine, but when I enter a role with a "special" role, it does not detect it, that is, it returns the error message that I configured to have the access prohibited to the link.

    
asked by Mixzplit 03.07.2016 в 18:49
source

1 answer

1

You have 3 options:

You can create permission groups within the same group

Route::group(['middleware' => ['role:admin|especial']], function() {
    // RUTAS PARA LOS 2 PERMISOS
    Route::get('/', '[email protected]');
    Route::get('/bar', '[email protected]');

    // RUTAS SOLO PARA ADMIN
    Route::group(['middleware' => ['role:admin']], function() {
        Route::get('/admin', '[email protected]');
    });
    // RUTAS SOLO PARA ESPECIAL
    Route::group(['middleware' => ['role:especial']], function() {
        Route::get('/especial', '[email protected]');
    });
});

Filter for a single route through the middleware

Route::group(['middleware' => ['role:admin|especial']], function() {
    // RUTAS PARA LOS 2 PERMISOS
    Route::get('/', '[email protected]');
    Route::get('/bar', '[email protected]');

    // FILTRO PARA LA RUTA SOLO ACCESIBLE POR ADMIN
    Route::get('/admin', ['middleware' => ['role:admin'], 'uses' => '[email protected]']);

});

Filter through the Entrust

// Redirecciona a /home si no es admin
Entrust::routeNeedsRole('admin*', 'admin', Redirect::to('/home'));

Route::group(['middleware' => ['role:admin|especial']], function() {
    // RUTAS PARA LOS 2 PERMISOS
    Route::get('/', '[email protected]');
    Route::get('/bar', '[email protected]');
});
    
answered by 20.10.2016 / 09:21
source