Download the PHP package hosseinhezami/laravel-permission-manager without Composer
On this page you can find all versions of the php package hosseinhezami/laravel-permission-manager. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download hosseinhezami/laravel-permission-manager
More information about hosseinhezami/laravel-permission-manager
Files in hosseinhezami/laravel-permission-manager
Package laravel-permission-manager
Short Description Advanced permission manager for Laravel.
License MIT
Informations about the package laravel-permission-manager
Laravel Permission Manager
A comprehensive and advanced permission management system for Laravel applications. This package provides a robust role-based access control (RBAC) system with support for wildcard permissions, blade directives, Artisan commands, and a fluent API.
Features
- Role-Based Access Control (RBAC): Assign multiple roles to users, and permissions to roles.
- Multiple Roles: Support for multiple roles per user.
- Route-Based Permissions: Permissions are tied to Laravel route names (e.g.,
users
). - Wildcard Support: Use wildcards for permissions (e.g.,
admin.*
,admin*
,*admin
,*admin*
) for flexible route matching. - Blade Directives: Easily check roles and permissions in Blade templates (
@hasRole
,@hasPermission
). - Facade Methods: Conveniently manage roles, permissions, and users via the
PermissionManager
facade. - Console Commands: Comprehensive Artisan commands for managing roles and permissions.
- Caching: Permissions are cached for performance.
- Exceptions: Custom exceptions for robust error handling.
- Multi-Guard Support: Works with Laravel's authentication guards.
- Export/Import: Export roles and permissions to JSON and import them back.
- Middleware: Protect routes with role or permission checks (
pm
,pm:role:admin|editor
). - User Trait: Adds role and permission methods to the User model.
- Easy Installation: Auto-discovery for easy installation.
Installation
-
Install the package via Composer:
-
(Optional) If Laravel's package auto-discovery is disabled, add the service provider and facade to
config/app.php
: -
Publish the configuration and migrations:
-
Run the migrations to create the necessary tables:
- Add the
PermissionTrait
trait to yourUser
model:
To run the install command which sets up the configuration and optionally adds the trait to your User model:
Configuration
After publishing the configuration file, you can customize the package behavior in config/permission-manager.php
:
Database Migrations
The package includes the following database migrations:
Usage
Blade Directives
Check for roles in your Blade templates:
Middleware
Protect your routes with middleware:
Artisan Commands
The package provides several Artisan commands for managing roles and permissions:
Facade Methods
Use the facade for programmatic management:
Wildcard Permissions
The package supports wildcard permissions for flexible route matching:
Trait Methods
The PermissionTrait
trait adds these methods to your User model:
Exceptions
The package includes custom exceptions for better error handling:
PermissionAlreadyExists
PermissionDoesNotExist
RoleAlreadyExists
RoleDoesNotExist
UnauthorizedException
Best Practices
- Use meaningful role slugs and permission routes
- Utilize wildcard permissions for related routes
- Regularly sync routes with permissions to keep them up to date
- Use the cache feature in production for better performance
- Handle exceptions appropriately in your application
Contributing
Please see CONTRIBUTING for details.
License
The MIT License (MIT). Please see License File for more information.
Support
If you have any questions or issues, please email [email protected] instead of using the issue tracker.