Download the PHP package panoscape/privileges without Composer
On this page you can find all versions of the php package panoscape/privileges. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download panoscape/privileges
More information about panoscape/privileges
Files in panoscape/privileges
Package privileges
Short Description Permission control system for Laravel
License MIT
Homepage https://github.com/seancheung/privileges
Informations about the package privileges
Privileges
Privilege and Group control for Laravel
Installation
You can install this package via composer using this command:
Register service provider:
config/app.php
If you need blade directives, also add this:
config/app.php
A middleware can also be registered:
app/Http/Kernel.php
Publish profile config:
Modify the published profile template to suit your application.
config/privileges_profile.php
Add Panoscape\Privileges\Privilege\UserEntity
trait to your user model, Panoscape\Privileges\Privilege\GroupEntity
trait to your group model, and Panoscape\Privileges\Privilege\PrivilegeEntity
trait to your privilege model.
If you have multiple privileges control flow or you prefer a different profile name, you may copy and modify the default profile template and rename it to something else, admin_profile
for example. Then defile a method named profile
in your related models and set them to the config name of your choice.
Here is an example of Admin
, Role
, Permission
(instead of User
,Group
,Privilege
):
config/admin_profile.php
app/Admin.php
app\Role.php
app\Permission.php
Migration
This package does not provide any migrations or commands. You should create three required models/migrations and two pivot tables by yourself. The minimal requirements of table structures are listed in the profile template.
Basic Usage
Access groups/privileges relationship of a user:
or via dynamic properties:
If you have different entity names other than the default User
, Group
, Privilege
, You should access the relationships by the table
values defined in your profile.
Example of Admin
, Role
, Permission
:
Group and Privilege validation
has:
all:
any:
Instead of the default name
column checking, you may specify which column to check:
validate:
With this method you can do complex checking
all:
equivalent to
any:
equivalent to
all + any:
equivalent to
group:
equivalent to
privilege:
equivalent to
group + privilege:
equivalent to
Column specification is also available:
Middleware
If you have registered the middleware, you can add it to any routes you'd like to guard with it.
Balde
If you have registered the blade service provider, you may guard your blade codes with @validate
, @group
and @privilege
.
Also your user entity need to implement Panoscape\Privileges\Privileged
interface in order to use these blade directives.
Blade directives:
Performance
joined 5 tables(2 of them are pivot tables) within one query:
joined 5 tables(2 of them are pivot tables) within two query:
joined 5 tables(2 of them are pivot tables) within two query:
Conclusion
Each any group costs one query;
All all group costs one query.