Conditional Eager loading issue

I am trying to eager load for table function in my MemberResource.php but I dont see table list after this. Since I have polymorphic realtionship, so i need to eager load conditionally and that is not working. Where i am going wrong. when I comment out conditional part of eager loading, I see table list.
public static function table(Table $table): Table
{
return $table
->modifyQueryUsing(function ($query){
$query->with([
'memberable',
'memberCreatedBy',
'memberUpdatedBy',
'platformTeamMemberAssignedBy',
'assignedPlatformTeamMembers',
]);

// Eager load specific relationships based on memberable_type
$query->when($query->getQuery()->where('memberable_type', Company::class)->exists(), function ($query) {
$query->with(['memberable.profile', 'memberable.profile.addresses']);
});

$query->when($query->getQuery()->where('memberable_type', User::class)->exists(), function ($query) {
$query->with('memberable.addresses');
});


return $query;

})
->columns([
public static function table(Table $table): Table
{
return $table
->modifyQueryUsing(function ($query){
$query->with([
'memberable',
'memberCreatedBy',
'memberUpdatedBy',
'platformTeamMemberAssignedBy',
'assignedPlatformTeamMembers',
]);

// Eager load specific relationships based on memberable_type
$query->when($query->getQuery()->where('memberable_type', Company::class)->exists(), function ($query) {
$query->with(['memberable.profile', 'memberable.profile.addresses']);
});

$query->when($query->getQuery()->where('memberable_type', User::class)->exists(), function ($query) {
$query->with('memberable.addresses');
});


return $query;

})
->columns([
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server