© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•3y ago•
9 replies
Miguel García

Filtering by a related table column changes the table id

Hi, I'm following the Owners, Pets, Treatments demo and I'm having issues creating a simple toggle filter by owner's email for the Patients resource.
Tables\Filters\Filter::make('owner_email')
    ->label('Owner email is John Doe')
    ->toggle()
    ->baseQuery(function (Builder $query): Builder {
        return $query
            ->join('owners', 'patients.owner_id', '=', 'owners.id');
    })
    ->query(function (Builder $query): Builder {
        return $query
            ->where('owners.email', '=', 'john@doe.com');
    }),
Tables\Filters\Filter::make('owner_email')
    ->label('Owner email is John Doe')
    ->toggle()
    ->baseQuery(function (Builder $query): Builder {
        return $query
            ->join('owners', 'patients.owner_id', '=', 'owners.id');
    })
    ->query(function (Builder $query): Builder {
        return $query
            ->where('owners.email', '=', 'john@doe.com');
    }),

My problem is that after applying filter, the Patients table now uses the owner's id instead of the patients id. What I'm doing wrong?
Screenshot_2023-11-23_at_11.44.01.png
Screenshot_2023-11-23_at_11.44.06.png
Screenshot_2023-11-23_at_11.41.08.png
Screenshot_2023-11-23_at_11.42.17.png
Solution
You are adding a join with a table that also has an ID. Try adding a
select('your_table.*')
select('your_table.*')
via the table query
Jump to solution
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Filtering by clicking on column
FilamentFFilament / ❓┊help
3y ago
search id column in table
FilamentFFilament / ❓┊help
3y ago
Struggling filtering a table
FilamentFFilament / ❓┊help
3y ago
Custom column - button - behaviour changes after filtering or paging
FilamentFFilament / ❓┊help
2y ago