Download the PHP package coffeecodemx/wildcard-permissions without Composer
On this page you can find all versions of the php package coffeecodemx/wildcard-permissions. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package wildcard-permissions
Laravel Wildcard Permission
A powerful permission management library for Laravel applications.
Features
- Role-based access control (RBAC)
- Fine-grained permission management
- Flexible permission assignment
- Easy integration with Laravel's authentication system
- Lightweight and efficient
Installation
You can install this package via Composer. Run the following command:
Then add the service provider in your Laravel project
Next you need to publish the configuration and migration files with the following command
Now you'll see a new configuration file in /config directory, just do the changes needed for table names and classes. A recommended change for a basic usage is to change under pivot_names.model_id to you model id which usually is user_id
Now run the migrations
Add the traits to the model you wish to have permissions
That's it!
Usage and examples
Create new Permission
To create a new permission you just need to run the following command.
Short name and description are very descriptive, however guard_name is the special one, this field will only accepts alphabetic upper and lowecase and : symbol to separate namespaces, modules, you name it!
You can combine multiple namespaces like this:
Find Permission
Since guard name is unique, you can easyly find a permission using guard name or if you want to find it using other fields just check the following examples.
Assign direct permissions to a Model
First your model should have the Trait HasPermissions, then is just
And if you want to revoke a permission is using the following
Create new Role
Roles are basically a collection of permissions and the way to create a new one is using the following command
Now for assigning or revoking permissions is the same as we do with models
or revoking permissions
Assigning roles to a user
First your model should have the Trait HasRoles, then is just
or you can unassign it
Check if your user has one or more roles
If you want to check for roles you have 3 operations
Check if the user has permissions
For checking permissions you can search by permission object, by guard_name or by wildcard
Middlewares
This package comes with RoleMiddleware
, PermissionMiddleware
and RoleOrPermissionMiddleware
middleware. You can add them inside your app/Http/Kernel.php file to be able to use them through aliases.
Middleware via Routes
You can protect your routes using middleware rules:
Use middleware static methods
For a better usage and to avoid confusion between laravel convetion using colon :
to separate the alias from the parameters and since the guard_names are using the same character for namespaces, alternatively you can use this syntax.
All versions of wildcard-permissions with dependencies
illuminate/auth Version ^8.12|^9.0|^10.0|^11.0
illuminate/container Version ^8.12|^9.0|^10.0|^11.0
illuminate/contracts Version ^8.12|^9.0|^10.0|^11.0
illuminate/database Version ^8.12|^9.0|^10.0|^11.0