steelants / laravel-tenant
Everything you need to start your Laravel journey.
2.1.0
2024-07-23 15:23 UTC
Requires
- laravel/framework: ^11.0
Requires (Dev)
README
Currently WIP
Created by: SteelAnts s.r.o.
Install
php artisan vendor:publish --tag=tenant-migrations
php artisan migrate
If your tenants have thier own SMTP settings, add following into mailers
array in config/mail.php
'smtp_tenant' => [
'transport' => 'smtp',
'host' => '',
'port' => env('MAIL_PORT', 587),
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => '',
'password' => '',
'timeout' => null,
'auth_mode' => null,
],
Usage
// Access tenant manager tenantManager() // Access current tenant object tenant() // is helper wrapper function for app(TenantManager::class)->getTenant();
Sending emails
// sending emial from tenants own SMTP server tenantManager()->mailer()->to(...)->send(...); // for sending emails from app's SMTP server use Laravel's default Mail class Mail::to(...)->send(...);
Running in console
By default, on web, tenant is set in TenantServiceProvider
by subdomain. To use tenant()
or tenantManager()->mailer()
in console,
for example in jobs, cron, ... you need to manualy set current tenant.
// Find your tenant $tenant = Tenant::find($tenantId); // Set as current tenant tenantManager()->set($tenant);
Development
Creation of symlinks for dev environment:
ln -s ./package/boilerplate/stubs/resources/ resources