hosseinhezami/laravel-permission-manager
users.edit) integrate seamlessly with Laravel’s route naming conventions, reducing friction in permission assignment.admin.*, *admin) and multi-guard authentication, making it adaptable to complex applications (e.g., multi-tenant SaaS). The fluent API and facade methods allow for both declarative (Blade) and programmatic (PHP) permission checks.roles, permissions, role_permissions, user_roles) are standardized and follow Laravel conventions, minimizing customization needs. The pivot tables enable efficient many-to-many relationships.pm, pm:role:admin, pm:permission:posts.create), which can be applied to routes without custom logic. This reduces boilerplate and centralizes permission checks.@hasRole and @hasPermission directives enable template-level access control, aligning with Laravel’s view layer. This is particularly useful for admin dashboards or role-specific UI elements.role:create, permission:sync-routes, user:assign-role) streamline permission management during development and deployment. The permission:sync-routes command is especially valuable for keeping permissions in sync with route changes.admin.*) offer flexibility, they may introduce performance overhead during permission checks, especially with large permission sets. Benchmarking is recommended for high-scale applications.cache_duration in config). Stale cache could lead to incorrect access control if not invalidated properly (e.g., after role/permission updates). Consider implementing event-based cache invalidation (e.g., listening to RoleUpdated events).role_permissions). If your application already uses similar table names, conflicts may arise. Review the schema before installation.sanctum, session) is critical to ensure permissions propagate correctly. The PermissionTrait must be applied to all user models used with supported guards.admin > editor) to optimize checks?permissions.route column) align with our permission naming conventions? If not, will we need to extend the Permission model?role:export/role:import commands)?pm middleware).@hasRole, @hasPermission directives).PermissionTrait).session, api) and third-party guards (e.g., Sanctum, Passport) if the PermissionTrait is applied to all relevant user models.PermissionManager::...) and Blade directives are IDE-friendly (e.g., PHPStorm autocompletion).PermissionManager facade or using the PermissionTrait directly.if ($user->is_admin) checks, custom middleware).users.create instead of can_edit_users).admin.* for all admin routes).pm middleware.@hasRole/@hasPermission.role:export, permission:export).can() methods).spatie/laravel-permission).cache_duration) doesn’t conflict with existing cache strategies.config/permission-manager.php) for customization needs.composer require hosseinhezami/laravel-permission-manager.php artisan vendor:publish --provider="HosseinHezami\PermissionManager\PermissionManagerServiceProvider" --tag="config,migrations".php artisan migrate.PermissionTrait to your User model (or all guard user models).config/permission-manager.php (e.g., cache_duration, wildcards).app/Http/Kernel.php:
'pm' => \HosseinHezami\PermissionManager\Middleware\PermissionMiddleware::class,
php artisan permission:sync-routes.php artisan role:create admin "Administrator" "Full access"
php artisan permission:create "users
How can I help you explore Laravel packages today?