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
toeknee5mo ago
How are you storing the team_id ? Just pass it in mutate before create to the selected id opposed to the creation.
PabloZagni
PabloZagniOP5mo 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
toeknee5mo ago
Are you using the Observer to set the team_id?
PabloZagni
PabloZagniOP5mo ago
I didn't apply a global Scope to the Issue class, but Fillament filters the Issue model
toeknee
toeknee5mo 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
PabloZagniOP5mo ago
Panel provider has ->tenant(Team::class);
toeknee
toeknee5mo ago
Correct, But even when doing that you tell the resources and the models to scope
PabloZagni
PabloZagniOP5mo 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
toeknee5mo ago
Ok, you can tell the resource to not scope So they are not filtered?
PabloZagni
PabloZagniOP5mo ago
I need to be filtered in index, but bypass current tenant on creating new record
toeknee
toeknee5mo 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
PabloZagni5mo ago
I solved it with this code
No description
Want results from more Discord servers?
Add your server