Recently I started to rebuild an ten-ish year old SaaS product in Laravel from an abandoned framework. The product needs multi tenancy with separate databases for each tenant.
The package provides an artisan command to run other artisan commands for each tenant in the application, for example to migrate each tenant: This command will loop through each tenant, sets the tenant as the current one and then performs the artisan command.
This is the full handle method: First we check if “currentTenant” is in available in the service container.
Now that everything is in place we can set the maintenance mode for a specific tenant like this: That’s all there is to add the possibility to set the maintenance mode for a specific tenant, while keeping the option to set the maintenance mode globally.