Download the PHP package smart-crowd/laravel-rbac without Composer
On this page you can find all versions of the php package smart-crowd/laravel-rbac. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download smart-crowd/laravel-rbac
More information about smart-crowd/laravel-rbac
Files in smart-crowd/laravel-rbac
Informations about the package laravel-rbac
Laravel RBAC
Laravel 5 RBAC implementation
Package was inspired by RBAC module from Yii Framework
Installation
-
Run
-
Add service provider and facade into
/config/app.php
file. -
Publish package configs
- Implement
Assignable
contract in your user model. And useAllowedTrait
.
Usage
-
Describe you permissions in
/Rbac/items.php
-
Use inline in code
-
Or in middleware
Of course, don't forget to register middleware in
/Http/Kernel.php
fileTo use route parameters in business rules as models instead just ids, you should bind it in
RouteServicePrivider.php
:There are 3 ways to bind permission name to action name:
- middleware paramenter
- bind they directelly in
/Rbac/actions.php
file - name permission like action, for example
article.edit
forArticleController@edit
action
-
Or in your views
If
rbac.shortDirectives
option are enabled, you can use shorter forms of directives, like this:
Context Roles
In some cases, you may want to have dynamically assigned roles. For example, the role groupModerator
is dynamic, because depending on the current group, the current user may have this role, or may not have. In our terminology, this role are "Context Role", and current group is "Role Context". The context decides which additional context roles will be assigned to the current user. In our case, Group
model should implement RbacContext
interface, and method getAssignments($user)
.
When checking is enough to send context model among other parameters:
But for automatic route check in middleware we usually send only post without group:
For this case you can implement RbacContextAccesor
intarface by Post
model. getContext()
method should return Group
model. Then you just have to send only the post, and context roles will be applied in middleware to:
You can not do that, if you send context with subject: