Download the PHP package fantismic/tenancy without Composer
On this page you can find all versions of the php package fantismic/tenancy. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download fantismic/tenancy
More information about fantismic/tenancy
Files in fantismic/tenancy
Package tenancy
Short Description A package to manage multi-tenancy in Laravel applications.
License MIT
Informations about the package tenancy
Fantismic/Tenancy
A Laravel package to build multi-tenant applications with separate databases per tenant on a single domain.
Features
- Tenant Provisioning: Create tenant-specific databases and database users automatically.
- Multi-Database Support: Each tenant gets its own MySQL database connection.
- Migrations & Seeders: Run migrations and seeders per tenant.
- Tenant Isolation: Use the
UsesTenantConnectiontrait to isolate Eloquent models to the tenant database. - Middleware: Automatically initialize tenant context based on authenticated user.
- Artisan Commands: Manage tenant migrations via console command.
- Admin Panel: Out-of-the-box routes, controllers, and views for tenant administration (list, migrate, sync users, delete).
Requirements
- PHP >= 8.1
- Laravel >= 10.0
- MySQL
Installation
Service Provider & Facades
This package uses auto-discovery. The following service providers and facades are registered:
-
Service Providers:
Fantismic\Tenancy\TenancyServiceProvider
-
Facades:
Tenancy(alias forFantismic\Tenancy\Helpers\TenantManager)TenantAdmin(alias forFantismic\Tenancy\Services\TenantAdminService)
Database Migrations
Publish and run the central migrations:
This will create:
tenantstabletenant_userpivot table- Tenant-specific migration stub directory at
database/migrations/tenant
Configuration
No configuration file is published. Tenant connection settings are stored in the connection JSON column of the tenants table. You can customize connection parameters when creating a tenant.
Usage
Creating a Tenant
Use the Tenancy facade to create a new tenant:
This will:
- Generate a UUID for the tenant.
- Create a database named
tenant_{uuid}and a useru_{uuid}with random password. - Store the connection JSON in the
tenantstable. - Run tenant migrations in
database/migrations/tenant. - Return the
Tenantmodel instance.
Artisan Command
Run migrations for an existing tenant:
Eloquent Models
Use the UsesTenantConnection trait on any model that should use the tenant database:
Middleware
Protect tenant routes and initialize tenant context:
Admin Panel
The package provides a simple administrative UI. Publish views:
Then visit /admin/tenants to manage tenants.
Supported actions:
- List tenants
- Migrate tenant database
- Sync users from central to tenant pivot
- Delete tenant and drop its database
Facades & Services
Tenancy(TenantManager): Tenant creation, migrations, and seeding.TenantAdmin(TenantAdminService): Fetch, migrate, sync users, and delete tenants.
Events & Listeners
The package listens to the Login event to set the current tenant in session:
Fantismic\Tenancy\Listeners\SetTenantSession
Contributing
Feel free to submit issues or pull requests. Follow PSR-12 coding standards and include tests for new features.
License
MIT License. See LICENSE for details.