· 5 min read · Muhammad Shah
Multi-tenant SaaS in Laravel with Stancl Tenancy: lessons from shipping ERPs
I've built multi-tenant platforms with Stancl Tenancy, including Solinvo, an ERP combining inventory, POS, sales, purchasing, warehousing and accounting, and the infrastructure behind Banoqabil LMS. Multi-tenancy is easy to start and hard to retrofit, so these are the decisions worth making early.
Pick the isolation model deliberately
- Single database with a tenant_id column: cheapest to run, but every query must be scoped, forever.
- Database per tenant: strongest isolation and simple per-customer backups, at the cost of more migrations and connections.
For business data like ledgers and invoices, separate databases make isolation much harder to get wrong. Stancl Tenancy supports both models, so you can choose per product.
Make tenant identification boring
Identify the tenant once, early in the request, by subdomain or domain, and let the package switch the database connection, cache prefix and file storage. Business code should never have to ask which tenant it's running for.
The parts that bite later
- Queued jobs: make sure each job runs in its tenant's context, or it will read the wrong database.
- Cache and storage: prefix keys and paths per tenant so data never leaks between customers.
- Migrations: run them for every tenant in your deploy, and keep them backwards-compatible.
- Central data: keep billing, plans and the tenant list in a central database, separate from tenant data.
Test isolation, not just features
Write tests that create two tenants and prove one can't see the other's records, files or cache entries. It's the most valuable test in a multi-tenant codebase, and the one most teams skip.
Getting these foundations right means the next hundred customers cost you configuration, not rewrites.
Keep reading
5 min read
Zero-downtime Laravel deploys to a VPS with GitHub Actions
Build once in CI, upload a release, switch a symlink atomically and roll back in seconds: the deploy setup I use for Laravel apps on a VPS.
4 min read
A technical SEO checklist for Laravel and Inertia sites
Server-side rendering, canonical URLs, structured data, sitemaps and SEO tests in CI: the checklist I followed building Trendivoa on Laravel and Inertia.