user3737083
user3737083

Reputation:

How can I assgin multiple role to any laravel route?

I created one middleware to check user roles("superadmin","admin" and "user").

And its working fine for one say for 'admin', if I use single role role.

Route::get('users',['middleware' => 'role:superadmin', function () {
    return view('users_list');
}]);

But the problem is to give access to multiple role here. I tried this but not working.

Route::get('users',['middleware' => 'role:superadmin,admin', function () {
    return view('users_list');
}]);

Although here I am getting role 'superadmin' not admin. But I think its wrong.

Please suggest me to give multiple role for any route.

Also I have gone through https://github.com/Zizaco/entrust but found many open issues https://github.com/Zizaco/entrust/issues. Please suggest me if you have any better idea than start with 'Zizaco'.

Upvotes: 2

Views: 1635

Answers (1)

Joost
Joost

Reputation: 761

You need to seperate the roles with an |.

like so:

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

Entrust documentation

Upvotes: 5

Related Questions