pierresilva / laravel-access-control
Laravel 7 Roles and Permissions
Installs: 52
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 1
Open Issues: 0
Type:package
Requires
- php: >=7.2.5
- illuminate/config: 7.*|8.*
- illuminate/database: 7.*|8.*
- illuminate/filesystem: 7.*|8.*
- illuminate/support: 7.*|8.*
This package is auto-updated.
Last update: 2024-11-23 21:51:22 UTC
README
Laravel 7 Access Control brings a simple and light-weight role-based permissions system to Laravel's built in Auth system. Laravel Access Control brings support for the following ACL structure:
- Every user can have zero or more permissions.
- Every user can have zero or more roles.
- Every role can have zero or more permissions.
- Every role can have one special flags, all-access or no-access
Quick Installation
-
composer require pierresilva/laravel-access-control
-
php artisan migrate
-
Add the
AccessControlTrait
trait to yourUser
model.
...
use pierresilva\AccessControl\Traits\AccessControlTrait;
class User extends Authenticatable
{
...
use AccessControlTrait;
...
}
Usage
Middleware
AccessControl provides middleware that you may assign to specific routes in your application. To register, simply append the following middleware to your app/Http/Kernel.php file under the $routeMiddleware property.
Check If User Has A Given Role
'has.role' => \pierresilva\AccessControl\Middleware\UserHasRole::class,
Check If User Has A Given Permission
'has.permission' => \pierresilva\AccessControl\Middleware\UserHasPermission::class,
Facade
AccessControl provides a facade to check user roles and permissions.
Check user has a role
\AccessControl::userIs('role.slug')
Check user has any of given roles
\AccessControl::userIs(['role.slug.1', 'role.slug.2'])
Check user if user has a permission
\Accesscontrol::userCan('permission.slug')
Check user if user has any of given permissions
\Accesscontrol::userCan(['permission.slug.1', 'permission.slug.2'])