Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ofureigbelos-9707055's avatar

Query builder on filament resource

hi everyone, i am having an issue using query builder for a filament table resource on page LearnersRource page generated using filament:

public static function table(Table $table): Table { return $table ->columns([ //All table columns and data ]) ->query(function (Builder $query){

            //$user = Auth::user();

            $user = auth('web')->user();
            
            if($user->isSuperAdmin()){
                return $query;
            }

            if($user->isEmployer()){
                return $query->where('employer_id', $user->employer_id);
            }

            return Learner::query()->where('1 = 0');


        })

}

Note isSuperAdmin & isEmployer method are underlined as undefined methods even when declared in user Model class as

public function isSuperAdmin(): bool
{
    return $this->hasRole('super_admin');
}

public function isEmployer(): bool
{
    return $this->hasRole('employer');
}

and the learner model class handles the relationship as:

public function user(): BelongsTo
{
    return $this->belongsTo(User::class);
}
0 likes
2 replies
s4muel's avatar

its just because the IDE doesnt know which class is the $user variable. try adding a phpdoc block to help it a bit

/** @var \App\Models\User $user */
$user = auth('web')->user();

if ($user->isSuperAdmin()){
    return $query;
}

if ($user->isEmployer()){
    return $query->where('employer_id', $user->employer_id);
}
1 like

Please or to participate in this conversation.