"The model [App\Models\Team] does not have a relationship named [leads]." (Multi-tenant + Modules)
I'm writing a Multi-tentant app with Filament V3, but this app uses the Modules structure (using nWidart/laravel-modules and savannabits/filament-modules libraries)
The problem is that Multi tenancy requires that the "Team" (so the tenant model) contains a relationship function to each of my Models, but in my case I can have "dynamic" models that can change by the Modules i'm using, so it's impossible to know and implement all the relationship methods in Teams (also this model potentially can get too long and a mess if the app gets more complex).
Is there anyway to workaround this or disable this requirement?
8 Replies
Any hint?
@Matheeus did You find solution for that? I have same case as You and so far i didn't find any solution for that :/
Unfortunately I didn't find any simple solution so I discarded the modular multi-tenant architecture.
Seems there's a way to achieve it but I didn't try to implement it, it needs the Reflector class that scans the Model folder and dynamically gets the Model names, but seems to be an approach that is not recommended by many developers, because it affects the performance of the Laravel framework
Probably the best way to achieve this is by using Polymorphic relationships but I'm not sure
Ohhh, ok.
For now i will add manually each relation with model in Team model but when app will be have several modules with 20+ modules will be harder to maintain that π¦
Maybe i will find some solution for that before that π
I can only suggest that, in my experience, laravel-modules works poorly together with multi-tenancy, probably the modules library isn't really made for this approach, as it hands very bad to handle the "change of context"
because every tenant has a database context and in the same time the modules have another context in context
this made like pretty impossible to use many artisan commands
For me multi-tenancy + modules was best option because i want to create "core app" and modules that will be add new functionalities to app because not every client will be need all functionalities that will be available.
It depends on your necessities, in my case the extreme level of complexity that this combo adds to the developing of every module/part of the application was not such as to justify its use.
I opted for throwing out the multi-tenancy, by managing it at a server level using different laravel databases/envs, also because it's incompatible with many major Filament libraries like Shield (for permissions)
" also because it's incompatible with many major Filament libraries like Shield (for permissions)"
From what i see bezhanSalleh/filament-shield supports multi tenancy
I think that i will be not able to throw out that, app instance will per country and each country will be have own sites (50+) where i need data separation most of the time, some models will be common for all sites
One of solution can be make a custom command for module like module:add-relation NewModule that will append to Team Model piece of code with relation π It's silly i know...