Download the PHP package bhhaskin/laravel-roles-permissions without Composer
On this page you can find all versions of the php package bhhaskin/laravel-roles-permissions. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download bhhaskin/laravel-roles-permissions
More information about bhhaskin/laravel-roles-permissions
Files in bhhaskin/laravel-roles-permissions
Package laravel-roles-permissions
Short Description Roles and permissions support for Laravel applications.
License MIT
Informations about the package laravel-roles-permissions
Laravel Roles & Permissions
Roles and permissions management for Laravel applications.
Installation
Optionally publish the configuration and migration stubs:
Run the migrations:
Setup
Apply the trait to any authenticatable model that should handle roles and permissions:
By default the package ships with Role and Permission Eloquent models. You can swap these (and the underlying table names) by publishing the config file.
Usage
Roles automatically inherit all attached permissions, so hasPermission will return true when a user has a role that grants the ability.
Roles and permissions include a generated uuid column, and the default route key is switched to use it so API responses can safely expose the identifier without leaking incremental IDs.
Laravel's class-based factory discovery is supported out of the box; pull in the package and you can call Role::factory() or Permission::factory() from your tests or seeders. A convenience database seeder (Bhhaskin\RolesPermissions\Database\Seeders\RolesPermissionsSeeder) is also provided—run it with php artisan db:seed --class="Bhhaskin\RolesPermissions\Database\Seeders\RolesPermissionsSeeder" to quickly populate sample data. If you prefer to customize them, publish the assets:
Configuration
Publish the config to tweak model classes, table names, or caching preferences. The cache section is reserved for future enhancements; for now it stays disabled by default.
Enable object-level assignments by setting object_permissions.enabled to true in the published config. When enabled you can scope roles and permissions to individual models:
If you need different role catalogs for different models (for example teams vs organizations) define role_scopes in the config:
Roles created with a matching scope value (or created through Role::factory()->forScope('team')) can then only be assigned when that context model is supplied, while standalone roles continue to work globally. You can query the catalog by scope using the provided helpers:
Scoped permission creation
Scoped permissions work the same way as scoped roles. You can generate them via the factories and attach them to matching roles:
To list abilities for a given tenant type you can chain the helpers:
All versions of laravel-roles-permissions with dependencies
illuminate/auth Version ^10.0 || ^11.0
illuminate/database Version ^10.0 || ^11.0
illuminate/support Version ^10.0 || ^11.0