Download the PHP package holoultek/laravel-capabilities without Composer
On this page you can find all versions of the php package holoultek/laravel-capabilities. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download holoultek/laravel-capabilities
More information about holoultek/laravel-capabilities
Files in holoultek/laravel-capabilities
Package laravel-capabilities
Short Description Laravel package to add roles and capabilities functionality for your project
License MIT
Informations about the package laravel-capabilities
Laravel Capabilities
A laravel package to add roles and capabilities functionality to your auth models.
Installation
To use the package:
Uuid Auth models
If you are using uuid instead of the normal integer id for your auth models, you should publish the migrations and update the columns.
Migrate the database
Then you have to publish the config files for roles and capabilities
This will publish 2 files:
1. capabilities.php
The capabilities are auto discovered via this config files; The key will be your controller name without 'Controller' word.
And the values will be an indexed array which describe the capability name as index and the methods in your controller as array for the value.
For Example:
This describes a "show dashboard" capability which controlled by "DashboardController", the "show" method
2. roles.php
You can provide here all the roles for your application as keys and its value will be a list of all capabilities defined in the previous step.
'capability' is the middleware.
As a final step you should add the access controlled middleware to your route
or as group
Fill the tables
After editing the config files you can run these commands in sequence to create all roles and capabilities defined
User Context Manager
This package includes a powerful UserContextManager that loads the authenticated user's roles and capabilities once per request. This avoids redundant database queries and provides a fast, consistent way to check permissions anywhere in your application (Controllers, Services, Policies, etc.).
The package automatically registers a UserContext facade for easy access.
Setup
To make the UserContextManager available on every request, you must register its initialization middleware as described above. Once configured, you can use the facade without any per-route setup.
Usage
Here are some examples of how to use the facade:
Check for a capability:
Check for a role:
Check for multiple roles (user must have at least one):
Check if the user is a "Chief" (superuser with all permissions):
The UserContextManager is automatically initialized for every authenticated web request, so you can use the facade without any additional setup.
Attaching and detaching
To attach or detach a capability
To attach or detach a capability
To check if auth model has a capability or role
Badges
Contact
If you have any questions or concerns, feel free to reach out to me at [email protected]
Or by visiting https://holoultek.com