Download the PHP package cuongnd88/lara-guardian without Composer
On this page you can find all versions of the php package cuongnd88/lara-guardian. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download cuongnd88/lara-guardian
More information about cuongnd88/lara-guardian
Files in cuongnd88/lara-guardian
Package lara-guardian
Short Description Laravel Guardian makes it easy to perform permission
License MIT
Homepage https://github.com/cuongnd88/lara-guardian
Informations about the package lara-guardian
Laravel Guardian
Laravel Guardian makes it easy to perform permission
1-Install cuongnd88/lara-repository using Composer.
2-Add the following service provider in config/app.php
3-Run make:guardian command
App/Traits provides QueryKit trait to empower Laravel models.
App/Guardian/Traits has a trait to support Laravel Guardian.
App/Http/Middlewares/GuardianMiddleware.php is to check user's permissions.
App/Models provides 5 models such as Action, Role, Group, Permission, Role.
database/migrations has 5 tables: actions, roles, groups, permissions, roles.
Sample Usage
Based on route's name, Lara Guardian checks user's permission. You must follow the rule in naming a route: $page.$action
You have to assign the guard middleware in your app/Http/Kernel.php file.
There is the relationship of Guardian's models
MEMO: the alias of actions, pages tables is used to name a route, therefore you need to enter lower-case letters, dash symbol instead of space.
Please add App\Guardian\Traits\HasGuardian.php into the model
The HasGuardian trait provides:
joinGroup($groupId) : user joins a group.
joinMultiGroups($groups) : user joins multi groups.
hasPermissions(array $where = [], string $action = null, array $select = []) : show user's permissions.
rightAccess(string $page = null, string $action = null) : check user has the permission to access.
Import/Export data
Currently, Lara Guardian imports array data (read files in config\guardian) into database, and exports data in DB to file by using simple command
--action= is import or export value.
model= is one or three values actions|pages|groups.
For example:
App\Traits\QueryKit.php support these useful methods in importing/exporting guardian data:
insertDuplicate(array $data, array $insertKeys, array $updateKeys) is insert new rows or update existed rows. The first argument consists of the values to insert or update, while second argument lists the column(s) that uniquely identify records within the associated table. The third argument is an array of the columns that should be updated if a matching record already exists in the database.
except(array $columns) is to retrieve a subset of the output data.