List Resources - GetTabs: modifyQueryUsing not working with relationships or scopes

Hi everyone,

I'm working on setting up multiple tabs in a List for a particular resource. The idea is to have each tab display Companies, filtered by their type. I've included a code snippet for your reference.
<?php

namespace App\Filament\Admin\Resources\CompanyResource\Pages;

use App\Filament\Admin\Resources\CompanyResource;
use Filament\Actions\CreateAction;
use Filament\Resources\Pages\ListRecords;
use Illuminate\Database\Eloquent\Builder;

class ListCompanies extends ListRecords
{
    protected static string $resource = CompanyResource::class;

    public function getTabs(): array
    {
        return [
            'manufacturers' => ListRecords\Tab::make('manufacturers')
                ->modifyQueryUsing(fn(Builder $builder) => $builder->onlyManufacturers()),
            'carriers' => ListRecords\Tab::make('carriers')
                ->modifyQueryUsing(fn(Builder $builder) => $builder->onlyCarriers()),
            'suppliers' => ListRecords\Tab::make('suppliers')
                ->modifyQueryUsing(fn(Builder $builder) => $builder->onlySuppliers()),
        ];
    }
}

When I navigate to the resource list, I run into an error mentioning an undefined method called onlyManufacturers, which is actually a scope in my model. I've also tried running the query without using the scope, but I'm still encountering issues.

I've attached a screenshot of the dd($builder) output as well, just in case it's helpful.

Is it possible that I'm missing something here, or could there be something off in the documentation?

Thanks in advance for your help!
image.png
image.png
Solution
Try
->modifyQueryUsing(fn (Builder $query) => $query->yourScope(),
. I think the injection should be $query. I could easily be wrong
Was this page helpful?