Download the PHP package binary-cats/laravel-rbac without Composer
On this page you can find all versions of the php package binary-cats/laravel-rbac. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download binary-cats/laravel-rbac
More information about binary-cats/laravel-rbac
Files in binary-cats/laravel-rbac
Package laravel-rbac
Short Description Laravel 11 enum-backed RBAC extension of spatie/laravel-permission
License MIT
Homepage https://github.com/binary-cats/laravel-rbac
Informations about the package laravel-rbac
Laravel RBAC
Enhance Laravel 11 with opinionated extension for spatie/laravel-permissions. Before your permission list grows and maintenance becomes an issue, this package offers simple way of defining roles and their permissions.
Installation
You can install the package via composer:
You can publish the config file with:
This is the contents of the published config file:
Usage
In a simple setup we usually have two basic parts of an RBAC: a permission and a role. Permissions are usually grouped by functional or business logic domain and a Role encapsulates them for a specific guard.
- Create Abilities
- Define Roles
- Connect the dots
Abilities
To avoid collision with spatie/laravel-permission
we are going to use BackedEnum
Ability enums to hold out enumerated permissions:
You can read more on using enums
as permissions at the official docs.
To create an Ability:
This will generate a PostAbility
in App\Abilities
:
Default stub contains fairly standard CRUD enumeration, generated using the name of the ability. Feel free to publish the stubs and adjsut as needed.
Defined Roles
As the name suggests, a DefinedRole
offers a mechanism to simplify the definition of all permissions needed for a given role.
To create an EditorRole
run:
This will generate an EditorRole
within App\Roles
:
This class contains a (now testable!) configuration definition for the role and its web
guard. Pretty neat!
We can now adjust it like so:
Now you are confident a specific role has specific permissions!
Connect the dots
Now that we have the abilities and roles, simply register role with rbac.php
config:
When you run rbac:reset
next time, your RBAC will be reset automatically.
Integration
I suggest adding the script to post-autoload-dump
of your composer.json
to make sure the RBAC is reset on every composer dump:
Testing
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email [email protected] instead of using issue tracker.
Postcardware
You're free to use this package, but if it makes it to your production environment we highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using.
Credits
- Cyrill N Kalita
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-rbac with dependencies
illuminate/contracts Version ^11.0
lorisleiva/laravel-actions Version ^2.8
spatie/laravel-collection-macros Version ^7.0
spatie/laravel-package-tools Version ^1.16
spatie/laravel-permission Version ^6.4