Download the PHP package winavin/permissions without Composer
On this page you can find all versions of the php package winavin/permissions. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download winavin/permissions
More information about winavin/permissions
Files in winavin/permissions
Package permissions
Short Description A lightweight, Enum-driven Roles & Permissions package for Laravel, designed for multi-model and multi-team systems without requiring database-stored role or permission definitions.
License MIT
Homepage https://github.com/winavin/permissions
Informations about the package permissions
Permissions
A lightweight, Enum-driven Roles & Permissions system for Laravel, designed to support multiple user models and multi-team setups without database-stored role and permissions definitions.
Unlike existing solutions such as santigarcor/laratrust, spatie/laravel-permission, JosephSilber/bouncer, which tightly couple roles and permissions to database entries or a single team model, this package offers a developer-first, elegant approach using modern PHP 8.1+ Enums and polymorphic teams.
Features
- ✅ Roles and Permissions are defined through PHP Enums — no database storage for definitions.
- ✅ Built-in team support with team_type and team_id fields.
- ✅ Automatically publishes Enum, Model, and Migration files specific to each model.
- ✅ Caching for extremely fast role and permission checks.
- ✅ Caching for fast permission and role checks.
- ✅ Fully supports multiple user models (e.g., User, Admin, etc.).
- ✅ Optional --path support for organized Enums and Models
How It Works
- You define Roles and Permissions as PHP Enums.
- Only assignments (which user has which role or permission) are stored in the database.
- Each Role Enum contains a permissions() method to map its permissions.
- Cache is automatically managed for faster lookups.
-
For each model, two tables are created:
- e.g. ,
- e.g. ,
Replace model_ with the lowercase version of your model's name.
Extending
Since the Enum and Model classes are published directly into your App namespace, you are free to extend them according to your needs.
Examples:
- Add methods like , , inside your Enums.
- Add fields like to your role/permission tables to implement auto-expiry logic.
- Set up scheduled jobs to auto-remove expired roles or permissions. (It is recommended to use or methods for removals, which automatically clear cache.)
This approach gives you full control while maintaining the package's performance and simplicity.
Installation
Install the package using Composer:
Publish the configuration file:
Setup
1. Publish Configuration
2. Configure your models and teams in the config file
3. Now run install coammand to create the necessary tables and models:
`
This will create the necessary database migrations, Pivot models, and enum classes for your user models and teams.
Alternate Option
1. Publish Migration & Model Classes
Use the following command to generate the database migration and model scaffolding for a user model:
Replaces {User Model} with your model prefix (e.g. User, Customer, Employee) whichever you want to assign roles and permissions.
This will publish following files
- migration file
- Model for Roles entry
- Model for Permissions Entry
2. Add Trait to User Models
Add the trait to your model:
3. Publish Enum Classes for Team
Use this command to create role and permission Enums for your teams.:
This will publish
- // Enum for Roles
- // Enum for Permissions
4. Define Permissions
You can create new Roles and Permissions cases in Enum. After that define permissions for Role using the permissions() method inside the corresponding Role Enum.
Usage
Assigning Roles and Permissions
Checking Roles and Permissions
For readability, you may also use:
You can also check for multiple roles or permissions:
Retrieving Roles and Permissions
You can retrieve a user's assigned roles and permissions. These methods return a Laravel Collection and accept an optional $team parameter to limit results to a specific team:
Retrieving Teams
If a user belongs to any teams via roles (or direct permissions mapped through roles), you can retrieve them:
Syncing Roles and Permissions
You can sync roles or permissions to replace the current ones:
This will remove all old roles/permissions and assign the new ones.
Removing Roles and Permissions
You can remove a role or permission individually:
All related cache keys will be automatically cleared when you remove a role or permission.
Overwriting (Optional)
You can overwrite following methods in trait as per your need.
Notes
- Cache is automatically managed internally to maintain speed.
- Whenever you assign, remove, or sync roles/permissions, caches are automatically invalidated.
- You should always use the provided methods (, , , , , ) to modify roles and permissions instead of manipulating database records manually.
Contributing
If you want to contribute to this package, feel free to submit a pull request or open an issue on GitHub.
License
This package is open-sourced software licensed under the MIT.