Download the PHP package althinect/enum-permission without Composer
On this page you can find all versions of the php package althinect/enum-permission. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download althinect/enum-permission
More information about althinect/enum-permission
Files in althinect/enum-permission
Package enum-permission
Short Description This package is to create permissions with enums
License MIT
Homepage https://github.com/althinect/enum-permission
Informations about the package enum-permission
Laravel Enum Permissions
A Laravel package to easily manage Permissions with Enums and sync these permissions to your database. This package is built on top of Spatie's Laravel-Permission package, providing an enum-based approach to permission management. It's fully configured via the config file located at config/enum-permission.php
.
Requirements
- PHP 8.1 or higher (required for Enums support)
- Laravel 10.0 or higher
- Spatie/Laravel-Permission package
Installation
This package automatically installs Spatie's Laravel-Permission package as a dependency, so you don't need to require it separately.
Spatie configs
You will need to run the migrations and add the necessary configs according to the Spatie Permissions documentation
After installation, publish the configuration file:
Then run the migrations to set up all required tables including the permissions tables from Spatie and the group column added by this package:
Configuration
The configuration file will be published to config/enum-permission.php
. Customize your permissions, models path, and other options there.
Configuration Options
Migrations
This package relies on the database tables created by the Spatie Laravel-Permission package and automatically adds a 'group' column to the permissions table for better organization.
When you install this package and run migrations, two things happen:
-
The Spatie migrations create the core permission tables:
permissions
- Stores all permissionsroles
- Stores all rolesmodel_has_permissions
- Maps permissions to users or other modelsmodel_has_roles
- Maps roles to users or other modelsrole_has_permissions
- Maps permissions to roles
- This package adds its own migration to enhance the permissions table:
- Adds a
group
column to thepermissions
table - Creates an index on the
group
column for faster queries
- Adds a
The group
column is used when sync_permission_group
is enabled in the config, allowing permissions to be organized by model name, which is especially useful for UI-based permission management systems.
Usage
Generating Permission Enums
The permission:make
command generates permission enums (and policies if requested) for your models.
Syncing Permissions to Database
The permission:sync
command scans for permission enums and syncs them to the database.
Using Generated Permissions
Directory Structure
After generation, your files will be organized as follows:
If your models use domain-driven structure, permission enums will follow the same structure:
Available Commands
permission:make {modelName?} {--P|policy} {--force}
- Generate permission enums and optional policiespermission:sync {--C|clean} {--path=} {--force}
- Sync permissions to database
Examples
Generated Permission Enum
Generated Policy
Permission Groups
When sync_permission_group
is enabled in the config, permissions will be grouped by model name, which is helpful for UI-based permission management:
This feature uses the group
column added to the permissions
table by this package's migration. The permissions are grouped automatically during the sync process:
This grouping makes it easy to:
- Create model-based permission management UIs
- Filter permissions by model in your admin panels
- Apply batch operations to all permissions of a specific model
Error Handling
The package includes comprehensive error handling:
- Database compatibility across PostgreSQL, MySQL, and other supported systems
- Graceful failure when encountering invalid classes
- File operation safeguards
- Exception reporting for debugging
Extending the Package
You can extend the package's functionality by:
- Customizing the permission stubs in the config file
- Adding custom permission groups
- Creating middleware that uses the permission enums
- Building custom UI components for managing permissions
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This package is open-source software licensed under the MIT license.
All versions of enum-permission with dependencies
illuminate/contracts Version ^10.0||^11.0||^12.0
spatie/laravel-package-tools Version ^1.16
spatie/laravel-permission Version ^6.0