This repository has been archived by the owner on Sep 17, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
4.1. Roles middleware
EL OUFIR Hatim edited this page Feb 24, 2019
·
1 revision
The roles middleware gives you the possibility to secure a route by specifying an array of roles and a type of grant access.
To use this middleware, you need to add it to your route with the following format:
Route::post('test', 'TestController@index')->middleware(['middleware' => 'roles:GRANT_TYPE,ROLE1,ROLE2,..']);
The first element of the roles middleware parameters is (optional) and can be all or any (if not provided, the default value will be any)
- all means that the user must have all the roles specified in the middleware to access the route
- any means that the user need to have at least one of the roles specified in the middleware to access the route
Example 1:
In the two following examples, the user need to have the role ROLE_ONE or the role ROLE_TWO or both to access the this route:
Route::post('test', 'TestController@index')->middleware(['middleware' => 'roles:any,ROLE_ONE,ROLE_TWO']);
Route::post('test', 'TestController@index')->middleware(['middleware' => 'roles:ROLE_ONE,ROLE_TWO']);
Example 2:
In the following example, the user must have both the role ROLE_ONE and the role ROLE_TWO to access the this route:
Route::post('test', 'TestController@index')->middleware(['middleware' => 'roles:all,ROLE_ONE,ROLE_TWO']);