Building a SaaS app with Laravel, FilamentPHP, and Multi-DB Tenancy
Package Version
V3 - V4
How can we help you?
Hi everyone π,
Iβm planning to build a SaaS application using:
Laravel (backend framework)
FilamentPHP (for the admin/dashboard panel)
Tenancy for Laravel (https://tenancyforlaravel.com/)
I want to set up a multi-database tenancy (each tenant has its own database), but Iβm not sure about the best way to:
Integrate FilamentPHP with a multi-DB tenant setup.
Manage tenant dashboards (separate panels or shared panel with tenant isolation).
Structure a small demo/reference SaaS website as a starting point.
If anyone has:
Example projects or documentation
Boilerplates/demos
Best practices for Laravel + Filament + multi-DB tenancy
β¦Iβd love your suggestions or references π
Thanks in advance! π
Tenancy for Laravel
Automatic & flexible multi-tenancy package for Laravel.
Automatically turn any Laravel application multi-tenant β no code changes needed. stancl/tenancy automatically switches database connections and all other things in the background, letting you leverage standard Laravel code into a full SaaS application. Most features out of all multi-tenancy packages. Single & multi-database tenancy.
1 Reply
It's a very deep topic. I joined a startup 6 months ago and I'm developing, from scratch, a multi-tenancy SaaS with Filament. After our research, we choose a single shared database paradigm. Things you have to consider:
If multiple databases:
1. Consider if is important to you to handle issues when you are deploying changes with migrations. Imagine if you have 25 databases and it runs correctly in 20... what about the other fives? how you will handle that types of issues? It's important for your business?.
2. Sometimes, the database isolation is mandatory for country legislation/industry restrictions/etc. In order to apply to any ISO certification.
3. We have a back office Filament panel where we can see our SaaS metrics and, since we have only one database, is easier to build queries across all our tenants.
If single shared database (our startup choose):
1. At first, we were very afraid of data isolation, but it hasn't been a problem with Laravel's scopes and observers.
2. You must test your application properly. We test data isolation and user authorization on every Filament resource. Any data leaks could be really damaging to our reputation as a startup.
3. If database instance has an issue or is down, all our clients gonna be affected. But, is not being a problem so far. We are using PostgreSQL and we have backups, replicas, etc. in any case.
Probably, you can handle all the points related to multiple databases that i've mentioned but could be a little bit tricky than single database.
There are a lot of others topics to consider but, there are what I remember now π