The stancl/tenancy package provides automatic multi-tenancy for your Laravel application:
- No model traits to change database connections
- No replacing Laravel classes with tenancy-aware classes
- Built-in tenant identification based on hostname, including second-level domains)
It works by using the current hostname as the tenant, switching database and Redis connections, and suffixing things like cache and filesystems.
The stancl/tenancy package comes with artisan commands and an API to do things like creating new tenants:
use Stancl\Tenancy\Tenant; Tenant::new() ->withDomains(['tenant1.yourapp.com', 'tenant1.com']) ->withData(['plan' => 'free']) ->save();
This package also provides a concept of tenant storage, which stores things like the tenant’s IDs, domains, plan, and you can even store tenant-specific application configuration:
Filed in: News
$tenant->put($key, $value); $tenant->set($key, $value); // alias for put() $tenant->put(['key1' => 'value1', 'key2' => 'value2']);
Join 31,000+ others and never miss out on new tips, tutorials, and more.
New Password Confirmation Flow for Logged In Users in Laravel 6.2
Laravel released v6.2 yesterday with a new password confirmation feature that enables you to require a logged-in user…
Laravel Ignition Introduces the ddd() Helper
Laravel Ignition introduces a global ddd() helper available in all Laravel 6 installations and applications that have…