exceptionacllaravel-5.5entrust

Laravel 5.5 Entrust using middleware to grant permissions on route groups fails


I'm using entrust for my laravel 5.5 project to provide an ACL system. As I try to use a middleware in my routes to filter access it falls in the following case

Route::group(['middleware' => ['role:admin', 'role:hr']],
            function () {

//other routes which should be checked by permission
});

if admin access routes which are inside of this method I get an exception

 Symfony \ Component \ HttpKernel \ Exception \ HttpException
No message

if I remove the second role access

Route::group(['middleware' => ['role:admin']],
            function () {

//other routes which should be checked by permission
});

than it works, but I need to split this route access on permissions an can be accessed jut by this 2 roles.

What I do wrong in this case?


Solution

  • You don't split the role checks into separate array entries.

    It is possible to use pipe symbol as OR operator:

    'middleware' => ['role:admin|root']

    To emulate AND functionality just use multiple instances of middleware

    'middleware' => ['role:owner', 'role:writer']

    Docs