Loading wrong model on infolist

Hey guys, I found some strange behavior in my app and I can't help it. I am trying to load all direct children and authenticated user here:
// UserResource.php
/** @return Builder<User> */
public static function getEloquentQuery(): Builder
{
return parent::getEloquentQuery()
->when(
auth()->user()->hasRole(UserRole::Broker),
fn (Builder $query) => $query
->where('parent_id', '=', auth()->id())
->orWhere('id', auth()->id()),
);
}
// UserResource.php
/** @return Builder<User> */
public static function getEloquentQuery(): Builder
{
return parent::getEloquentQuery()
->when(
auth()->user()->hasRole(UserRole::Broker),
fn (Builder $query) => $query
->where('parent_id', '=', auth()->id())
->orWhere('id', auth()->id()),
);
}
Inside my users table I see 3 users: Parent (auth one), Child 1 and Child 2. When I click on parent or child 1, I see infolist for these models, but when I click on child 2 it still give me infolist with child 1. Although I can see child id 2 in the url. I am using this package: https://github.com/staudenmeir/laravel-adjacency-list Can you help point me in the right direction?
GitHub
GitHub - staudenmeir/laravel-adjacency-list: Recursive Laravel Eloq...
Recursive Laravel Eloquent relationships with CTEs - staudenmeir/laravel-adjacency-list
1 Reply
Trauma Zombie
Trauma ZombieOP7mo ago
When I remove ->orWhere('id', auth()->id()), part it works just fine, but I want to include auth user inside this query.
Want results from more Discord servers?
Add your server