Settings with Tenancy for Laravel #39
-
Hi, i use "Spatie Settings" and "Stancl Tenancy for Laravel". I face the following problem: How do I have to adapt the config so that the settings are saved in the tenant database? Thanks in adavance. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 12 replies
-
Hi @xemedia, We had the same problem in the project this package was built for. Though we're using our own spatie/multitenancy package I think the setup is the same. Within the config of the package you can set a model that will be used for stroring the settings (https://github.com/spatie/laravel-settings#repostitories). You should in a multi-tenancy setup create your own model which extends from the package model. In this model you can overwrite the connection to the correct database that should be used for the tenant. |
Beta Was this translation helpful? Give feedback.
-
Hello @rubenvanassche, I came across a similar problem. In my application, I use "Spatie Settings" and "Stancl Tenancy for Laravel" (multiple databases) so I created a "settings" table in each of the Tenant's databases. My problem was with caching the settings (using Redis). I needed to prefix the redis key for each Tenant with their UUID. I tried updating the "settings.cache.prefix" in the config file after resolving the Tenant using the solution provided in Stancl Tenancy for Laravel docs. The solutions I have thought of are:
In my opinion, the second solution requires more effort therefore I chose the first one. I have already forked the repo but I have not opened any Issue ticket or created any PR. Do you think this is necessary? |
Beta Was this translation helpful? Give feedback.
-
I'm having a weird problem when using the The weird part is, that tenancy works just fine on every other table and even in the same This is an old discussion, but I was wondering if you guys have any clues about where the problem may lie. Thank you |
Beta Was this translation helpful? Give feedback.
Hi @xemedia,
We had the same problem in the project this package was built for. Though we're using our own spatie/multitenancy package I think the setup is the same. Within the config of the package you can set a model that will be used for stroring the settings (https://github.com/spatie/laravel-settings#repostitories). You should in a multi-tenancy setup create your own model which extends from the package model. In this model you can overwrite the connection to the correct database that should be used for the tenant.