F
Filament2w ago
Pscl

Issue with relation loading when using an action with multi tenancy.

- You have a ViewPage with relational content that uses withoutGlobalScope('tenancy') to show data from other tenants - If you perform an Action, you will get the issue that the relational data is not loaded any more.
Attempt to read property "model_id" on null
Attempt to read property "model_id" on null
What is the best practices here? Somehow the Infolist is reloading its content, but without the relations defined in Resource:
public static function getEloquentQuery(): Builder
{
return parent::getEloquentQuery()

->forCurrentAgency()
->withoutTenancyScope()
->with([
'assignment' => fn ($q) => $q->withoutTenancyScope(),
'assignment.agency' => fn ($q) => $q->withoutTenancyScope(),
'assignment.customer' => fn ($q) => $q->withoutTenancyScope(),
'assignment.branch' => fn ($q) => $q->withoutTenancyScope(),
'profile' => fn ($q) => $q->withoutTenancyScope(),
'profile.agency' => fn ($q) => $q->withoutTenancyScope(),
'profile.availabilities' => fn ($q) => $q->withoutTenancyScope(),
'requests' => fn ($q) => $q->withoutTenancyScope(),
]);
}
public static function getEloquentQuery(): Builder
{
return parent::getEloquentQuery()

->forCurrentAgency()
->withoutTenancyScope()
->with([
'assignment' => fn ($q) => $q->withoutTenancyScope(),
'assignment.agency' => fn ($q) => $q->withoutTenancyScope(),
'assignment.customer' => fn ($q) => $q->withoutTenancyScope(),
'assignment.branch' => fn ($q) => $q->withoutTenancyScope(),
'profile' => fn ($q) => $q->withoutTenancyScope(),
'profile.agency' => fn ($q) => $q->withoutTenancyScope(),
'profile.availabilities' => fn ($q) => $q->withoutTenancyScope(),
'requests' => fn ($q) => $q->withoutTenancyScope(),
]);
}
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?