Laravel middleware

0

I have a question a bit silly, the question is that I am ready to create the filter by roles in Laravel, I have created a middleware for the filter of roles in the routes and up to here everything OK.

The problem comes when I want to make this filter

Route::group(['middleware' => ['auth', 'roles'],'roles' => ['cliente','cliente_tipo2'],'prefix' => 'descargas'], function () { 
    // Index
    Route::get('/', 'DescargasController@indexView')->name('indexDescargas');
    Route::group(['middleware' => ['auth', 'roles'],'roles' => ['cliente_tipo2'],'prefix' => 'privado'], function () { 
        Route::get('/', 'DescargasController@privadoView')->name('indexDescargasprivado');
    });
});

The question is that to enter the root of the first / within the first group, control those two roles OK (does not let others in), the problem arises in the second group, which instead of allowing only the role "client_type2" allows all of the above group (in this case "client" and "client_type2") to pass, despite being in another group with other middleware.

Any suggestions?

    
asked by David 10.07.2018 в 10:09
source

1 answer

-1

Thanks to partner Jorge Bowen the problem was to use the same middelware inside another.

This is how it was:

Route::group(['middleware' => ['auth', 'roles'],'roles' => ['cliente','cliente_tipo2'],'prefix' => 'descargas'], function () { 
    // Index
    Route::get('/', 'DescargasController@indexView')->name('indexDescargas');
    Route::group(['middleware' => ['auth', 'subroles'],'subroles' => ['cliente_tipo2'],'prefix' => 'privado'], function () { 
        Route::get('/', 'DescargasController@privadoView')->name('indexDescargasprivado');
    }); });

At the request of the comrade of the first comment, I edit how it ended up, simply duplicate the Middleware class, changing "roles" to "subroles" so that it was not the same class and worked well.

Highly recommended for permissions that depend on others, or, to avoid duplicating URLs.

Greetings

    
answered by 10.07.2018 / 10:31
source