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
Solution:
I solved it with this code
No description
Jump to solution
13 Replies
toeknee
toeknee2w ago
How are you storing the team_id ? Just pass it in mutate before create to the selected id opposed to the creation.
PabloZagni
PabloZagni2w ago
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.
toeknee
toeknee2w ago
Are you using the Observer to set the team_id?
PabloZagni
PabloZagni2w ago
I didn't apply a global Scope to the Issue class, but Fillament filters the Issue model
toeknee
toeknee2w ago
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
PabloZagni
PabloZagni2w ago
Panel provider has ->tenant(Team::class);
toeknee
toeknee2w ago
Correct, But even when doing that you tell the resources and the models to scope
PabloZagni
PabloZagni2w ago
Issues are filtered automatically by this tenant... if I remove this line, Issues are not filtered I didn't set any global scope
toeknee
toeknee2w ago
Ok, you can tell the resource to not scope So they are not filtered?
PabloZagni
PabloZagni2w ago
I need to be filtered in index, but bypass current tenant on creating new record
toeknee
toeknee2w ago
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
PabloZagni
PabloZagni2w ago
I solved it with this code
No description