Special Tenant Case
Hi. I'm developing an Issue tracking system.
Each user belongs to a Team (Sales, Marketing, Development, Support, etc).
Issue model has: title, description, priority, team_id
Any user can create an Issue to other Teams.
But, when the Issue is created, since Team is the tenant, team_id is set to my current tenant instead the team selected in the form.
Is there a way to save the Issue to the database with the selected team_id and not the current tenant?
Thanks
13 Replies
How are you storing the team_id ? Just pass it in mutate before create to the selected id opposed to the creation.
In CreateIssu, the mutateFormDataBeforeCreate recibes the $data array with the value in the Select, but it's saved with the current tenant. I suppose Filament sees that Team is the tenant and saves it in the Issue.
Ok so the global scope is applied to the model right? as per:
https://filamentphp.com/docs/3.x/panels/tenancy#simple-one-to-many-tenancy
Are you using the Observer to set the team_id?
I didn't apply a global Scope to the Issue class, but Fillament filters the Issue model
So filament does filter if you apply the tenancy, but it shouldn't be passing the team_id on creation etc, that's usually handled in other scopes lasttime I checked. But I could be wrong
Panel provider has ->tenant(Team::class);
Correct, But even when doing that you tell the resources and the models to scope
Issues are filtered automatically by this tenant...
if I remove this line, Issues are not filtered
I didn't set any global scope
Ok, you can tell the resource to not scope So they are not filtered?
I need to be filtered in index, but bypass current tenant on creating new record
I don't think the standard scope does what you say... but lets say it does. Disable the scope on the current resource as per the docs, then set a default tenant on the filters? or adjust the index query to manually scope the result to the current.
Solution
I solved it with this code