klc / permission
permission package for laravel
Installs: 26
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/klc/permission
Requires
- php: ^8
- illuminate/config: ^10.0
- illuminate/console: ^10.0
- illuminate/database: ^10.0
- illuminate/filesystem: ^10.0
- illuminate/redis: ^10.0
- illuminate/support: ^10.0
- klc/data-chain: ^1.0
README
composer require klc/permission
php artisan migrate
KLC\PermissionTrait add to user model
How To Use
example :
roles table :
| id | name | slug |
|---|---|---|
| 1 | Admin | admin |
| 2 | Client | client |
user_role table :
| user_id | role_id |
|---|---|
| 1 | 1 |
| 1 | 2 |
| id | name | slug |
|---|---|---|
| 1 | Foo | foo |
| 2 | Bar | bar |
| 3 | Baz | baz |
| 4 | Other | other |
role_permission table:
| role_id | permission_id |
|---|---|
| 1 | 1 |
| 1 | 2 |
| 2 | 4 |
| permission check: |
$user = User::where('id', 1)->first(); dump($user->hasPermission('foo')); dump($user->hasPermission('bar')); dump($user->hasPermission('baz')); dump($user->hasPermission('other'));
output:
true true false true
role check:
$user = User::where('id', 1)->first(); dump($user->hasRole('admin')); dump($user->hasRole('client')); dump($user->hasRole('foo'));
output:
true true false