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