Download the PHP package pierresilva/laravel-sentinel without Composer
On this page you can find all versions of the php package pierresilva/laravel-sentinel. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download pierresilva/laravel-sentinel
More information about pierresilva/laravel-sentinel
Files in pierresilva/laravel-sentinel
Package laravel-sentinel
Short Description Laravel 5 Roles and Permissions
License MIT
Informations about the package laravel-sentinel
Sentinel
Sentinel brings a simple and light-weight role-based permissions system to Laravel's built in Auth system.
Sentinel brings support for the following ACL structure:
- Every user can have zero or more roles.
- Every role can have zero or more permissions.
Permissions are then inherited to the user through the user's assigned roles.
Quick Installation
Begin by installing the package through Composer. The best way to do this is through your terminal via Composer itself:
Once this operation is complete, simply add the service provider to your project's config/app.php
file and run the provided migrations against your database.
Service Provider
Facade
Then open the Kernel.php file in app\Http\Kernel.php and add this to user it as middleware :
routeMiddleware
Migrations
You'll need to run the provided migrations against your database. Publish the migration files using the vendor:publish
Artisan command and run migrate
:
Usage
Sentinel package comes bundled with a SentinelTrait file to be used within your User's Model file. This trait file provides all the necessary functions to tie your users in with roles and permissions.
Example User Model
SentinelTrait
The following methods will become available from your User model.
- isRole($roleSlug)
- can($permission)
- assignRole($roleId)
- revokeRole($roleId)
- revokeAllRoles()
- syncRoles([$roleIds])
isRole($roleSlug)
Checks if the user is under the given role.
You may also use magic methods:
can($permission)
Checks if the user has the given permission(s). You may pass either a string or an array of permissions to check for. In the case of an array, ALL permissions must be accountable for in order for this to return true.
or
assignRole($roleId)
Assign the given role to the user.
Revokes the given role from the user.
revokeAllRoles()
Revokes all roles from the user.
syncRoles([$roleIds])
Syncs the given roles with the user. This will revoke any roles not supplied.
Role Permissions
The bundled Role model has easy to use methods to manage and assign permissions.
- can($permission)
- getPermissions()
- assignPermission($permissionId)
- revokePermission($permissionId)
- revokeAllPermissions()
- syncPermissions([$permissionIds])
can($permission)
Checks if the role has the given permission(s). You may pass either a string or an array of permissions to check for. In the case of an array, ALL permissions must be accounted for in order for this to return true.
getPermissions()
Retrieves an array of assigned permission slugs for the role.
assignPermission($permissionId)
Assigns the given permission to the role.
revokePermission($permissionId)
Revokes the given permission from the role.
revokeAllPermissions()
Revokes all permissions from the role.
syncPermissions([$permissionIds])
Syncs the given permissions with the role. This will revoke any permissions not supplied.
Facade Reference
Sentinel package comes with a handy Facade to make checking for roles and permissions easy within your code.
- Sentinel::can($permissions)
- Sentinel::canAtLeast($permissions)
- Sentinel::isRole($role)
Sentinel::can($permissions)
Checks if the current user can perform the provided permissions.
Parameters
- $permissions (array or string) Permission(s) to check for. Required. Returns Boolean Example
Sentinel::canAtLeast($permissions)
Checks if the current user can at least perform one of the provided permissions.
Parameters
- $permissions (array) Permissions to check for. Required. Returns Boolean Example
Sentinel::isRole($role)
Checks if the current user has the given role.
Parameters
- $role (string) Role (slug) to check for. Required. Returns Boolean Example
Template Helpers
Sentinel comes bundled with custom template methods to easily check for permissions and roles from within your view files for both Blade.
can($permissions)
Blade
All versions of laravel-sentinel with dependencies
illuminate/database Version 5.3.*
illuminate/support Version 5.3.*
illuminate/filesystem Version 5.3.*
illuminate/config Version 5.3.*