Doubts with getEloquentQuery()

I have a question, the getNavigationBadge, counts all the unprocessed records, but without filtering by employee in case that he is not an administrator. How could I make it filter without having to add the admin condition to getNavigationBadge?
public static function getEloquentQuery(): Builder
{
if (isAdmin()) {
$query = parent::getEloquentQuery()
->withoutGlobalScopes([
SoftDeletingScope::class,
]);

} else {
$query = parent::getEloquentQuery()->whereBelongsTo(auth()->user(), 'employee')
->withoutGlobalScopes([
SoftDeletingScope::class,
]);

return $query;
}

protected static function getNavigationBadge(): ?string
{
return parent::getEloquentQuery()->where('is_processed', 0)->count();
}
public static function getEloquentQuery(): Builder
{
if (isAdmin()) {
$query = parent::getEloquentQuery()
->withoutGlobalScopes([
SoftDeletingScope::class,
]);

} else {
$query = parent::getEloquentQuery()->whereBelongsTo(auth()->user(), 'employee')
->withoutGlobalScopes([
SoftDeletingScope::class,
]);

return $query;
}

protected static function getNavigationBadge(): ?string
{
return parent::getEloquentQuery()->where('is_processed', 0)->count();
}
2 Replies
awcodes
awcodes2y ago
Shouldn’t your getNavigationBadge return getEloquentQuery() on your class, otherwise it’s ignoring your logic and just chaining off the parent.?
Dan Harrin
Dan Harrin2y ago
return static::getEloquentQuery(
Want results from more Discord servers?
Add your server