Package Data | |
---|---|
Maintainer Username: | joshbrw |
Maintainer Contact: | josh@joshbrown.me (Josh Brown) |
Package Create Date: | 2017-09-08 |
Package Last Update: | 2017-09-08 |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-15 15:05:19 |
Package Statistics | |
---|---|
Total Downloads: | 5,040 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 2 |
Total Watchers: | 1 |
Total Forks: | 0 |
Total Open Issues: | 0 |
This package provides a simple way of registering permissions, organising them by group and then retrieving all permissions. These permissions can then be assigned to User/Role entities and used for Access Control logic.
composer require joshbrw/laravel-permission-manager
config/app.php
to ensure that the container bindings etc are loaded:
'providers' => [
...
Joshbrw\LaravelPermissions\LaravelPermissionManagerServiceProvider::class,
]
Permissions
facade if you'd rather use Permission::registerPermissions()
rather than using the PermissionManager
directly:
'aliases' => [
...
'Permissions' => Joshbrw\LaravelPermissions\Facades\Permissions::class,
]
Permissions should usually be registered in the boot()
method ophpuf a Service Provider - this ensures that this package has been able to register itself using it's own register()
method first.
The simplest way of registering permissions is using the Permissions
facade. The following example registers the user.list
and user.create
permissions within the User
group:
use Permissions;
use Joshbrw\LaravelPermissions\Permission;
class MyProvider extends ServiceProvider {
public function boot()
{
Permissions::register('User', [
new Permission('user.list', 'List Users', 'This allows a User to list other Users.'),
new Permission('user.create', 'Create Users', 'This allows a User to create another User.'),
]);
}
}
You can also use the RegistersPermissions
trait if you're not a fan of Facades, for example:
use Joshbrw\LaravelPermissions\Traits\RegistersPermissions;
use Joshbrw\LaravelPermissions\Permission;
class MyProvider extends ServiceProvider {
use RegistersPermissions;
public function boot()
{
$this->registerPermissions('User', [
new Permission('user.list', 'List Users', 'This allows a User to list other Users.'),
new Permission('user.create', 'Create Users', 'This allows a User to create another User.'),
]);
}
}