Download the PHP package vimatech/laravel-membership without Composer
On this page you can find all versions of the php package vimatech/laravel-membership. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download vimatech/laravel-membership
More information about vimatech/laravel-membership
Files in vimatech/laravel-membership
Package laravel-membership
Short Description Polymorphic memberships for Laravel: who belongs to what, and with which role. Enum roles, role hierarchy, guards, policy helpers, events and soft deletes, across teams, projects and workspaces.
License MIT
Homepage https://github.com/vimatech-io/laravel-membership
Informations about the package laravel-membership
Polymorphic memberships for Laravel
Laravel Membership lets you attach members and roles to any Eloquent model: organizations, teams, projects, workspaces, communities, or anything else.
It answers who belongs to what and with which role, nothing more.
Why Laravel Membership?
Most Laravel apps eventually need to answer:
- Who belongs to this organization?
- What role does this user have in this project?
- Can we prevent removing the last owner?
- Can the same membership logic work for teams, projects and workspaces?
Laravel Membership provides a small backend-only layer for that.
Feature Matrix
| Feature | Supported |
|---|---|
| Polymorphic memberships | ✅ |
| Enum roles | ✅ |
| Role hierarchy | ✅ |
| Guards (last owner, etc.) | ✅ |
| Events | ✅ |
| Scopes | ✅ |
| Soft deletes | ✅ |
| Policy helpers | ✅ |
| Invitations | ➕ (use Laravel Invitation) |
| Permissions | ❌ (use Spatie) |
| Billing | ❌ |
| UI | ❌ |
Laravel Membership vs Permissions
Laravel Membership manages:
- who belongs to what
- which role they have
Permission packages (like Spatie) manage:
- what users can do
They are complementary, not competing.
Use Cases
- SaaS organizations
- Teams
- Projects
- Workspaces
- Communities
- Collaborative apps
- Multi-tenant applications
- Agency client portals
- Internal company tools
Requirements
- PHP 8.3+
- Laravel 11, 12 or 13
Installation
The package loads its own migration automatically, so a fresh application only needs:
Publish config
Ordering the migration against your own
The package migration has no timestamp prefix, so Laravel runs it after every timestamped migration your application ships. On a fresh database this fails if one of your own migrations alters memberships, or declares a foreign key to it: the table does not exist yet at that point.
If that is your case, publish the migration under a name that sorts before your own, and stop the package from loading its copy:
Do both. Publishing without disabling run_migrations runs the migration twice and fails with table "memberships" already exists. Disabling it without publishing leaves nothing that creates the table.
On a database that already recorded create_memberships_table, do not run the published migration: rename the recorded row instead.
Usage
Make a model have members
Make a model act as a member
Create a roles enum (optional)
You can also use plain strings: enums are optional.
Add a member
Remove a member
Update a role
Check membership
Query members
Query memberships from member side
Scopes
Policy helpers
Facade (optional)
Complete Example
Events
The following events are dispatched:
| Event | When |
|---|---|
MemberAdded |
After a member is added |
MemberRemoved |
After a member is removed |
MemberRoleUpdated |
After a member's role is changed |
Each event contains the Membership instance and an optional $actor.
Guards
Guards are configurable protections in config/membership.php:
When prevent_self_demotion or prevent_role_escalation are enabled, pass an $actor:
Configuration
Soft Deletes
By default, removing a member permanently deletes the row. To keep membership history instead, enable soft deletes:
-
Set
'soft_deletes' => trueinconfig/membership.php - If your app is already in production, create a migration:
If you enable
soft_deletesbefore running your initial migration, the column is added automatically.
Once enabled:
Philosophy
Laravel Membership is intentionally minimal.
The package focuses on:
- Memberships
- Roles
- Role hierarchy
- Membership guards
Design principles:
- Backend-only, UI agnostic
- No auth assumptions
- No User model assumptions
- No permissions system
- No billing assumptions
- Enum-friendly roles
- Polymorphic by default
- Laravel-native API
- Clean and testable actions
It does not aim to become a permissions framework, a billing system, a UI framework, or a complete SaaS platform.
Testing
Contributing
Contributions are welcome.
Please ensure:
- Tests pass (
composer test) - PHPStan passes (
composer analyse) - Code style is formatted with Pint (
composer format)
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our Security Policy for reporting vulnerabilities.
License
The MIT License (MIT). Please see License File for more information.
Credits
Built and maintained by Vimatech. Created by Adel Zemzemi, Laravel SaaS architect.
All versions of laravel-membership with dependencies
illuminate/database Version ^11.0|^12.0|^13.0
illuminate/support Version ^11.0|^12.0|^13.0
illuminate/contracts Version ^11.0|^12.0|^13.0