Reputation: 2687
I have a Laravel 5.2 application using the Auth functionality provided by Laravel. For roles and permissions I'm using laravel-permission. I have defined 3 roles: admin, seller, buyer.
I was looking for a solution to be able to specify a role per route. So that I have a group of routes only accessible for user with role 'admin', a group of routes only accessible for user with role 'seller' and a group of routes only accessible to users with role 'buyer'.
I was thinking to define a separate middleware for admin, buyer and seller and use that for the routes. Or is the better way to define 1 middleware 'roles' that differentiates between the roles? Any better ways?
Upvotes: 0
Views: 464
Reputation: 521
You can make a middleware that takes parameters. Then you can do something like
'middleware' => 'role:role_name',
a single middleware with params passed should do fine
Upvotes: 1