I want to do multi db multi tenancy for a saas type shop app so that users is in main db, and users login using this table, and all shops have different db and users_table have shops db id, and all the shops regarded model uses tenant connection.
I tried using Stancl/Tenancy but its all about domains and subdomains, i want it to be done using single domain and use users_table to store tenant_id and tenant_db_name and initialize tenant from there. If its doable without using tenancy package also its fine. I am new to laravel so an example will be kindly appreciated.
This answer is late, but it will help future noobs like me.
I am building a SAAS application using Laravel, where my requirement is to use a single domain for the central and tenant apps, and each tenant should have it's own database. I came across the stancl/tenancy Laravel package. The problem is that some people, like me, don't understand the documentation due to a lack of experience and language. So here I would try to make it a simple step-by-step guide.
Step 1: install fresh Laravel
Step 2: install laravelfortenancy package
Run the Required Necessary commands
Then add the service provider to your config/app.php file:
Now, as my requirement was to use a single domain with multi-database tenancy,. The default behaviour of the package is to use the web.php file for central routes and tenant.php for tenant routes. For that, I discarded the tenant.php file and used web.php for both the tenant and central applications.
make customer middleware using command
In verifyTenant, paste this code
In web.php all the routes belongs to central just on bottom of web.php paste this code. This is specific middleware you can put all tenants route.
This way when you hit any route maybe it central or tenant it filtered and secured by middleware.