© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•3y ago
Rawrocopter

Select Filter with Custom FK

I am adding a select filter that I think should be pretty standard, but I will admit that I am pretty new to Filament.

I have 2 related models:

SlackUser, which has a PK of
id
id
, but a unique id of
slack_id
slack_id
.

I have a relationship from another model that uses this unique key, rather than the primary key.

public function slackUser()
{
    return $this->belongsTo(SlackUser::class, 'sender', 'slack_id');
}
public function slackUser()
{
    return $this->belongsTo(SlackUser::class, 'sender', 'slack_id');
}


And in Filament, I am trying to use this relatioship as a filter to be able to select based on Slack user. Filter code looks like this:

->filters([
    SelectFilter::make('sender')
        ->relationship('slackUser', 'name')
])
->filters([
    SelectFilter::make('sender')
        ->relationship('slackUser', 'name')
])


The names of the users display properly, but the filter doesn't seem to be working properly. The URL that is generated when applying the filter looks correct to me:

?tableFilters[sender][value]=ABC123
?tableFilters[sender][value]=ABC123


but if I log out the query, it doesn't seem to be using the custom owner key that is provided in the relationship:

SELECT
    count(*) AS aggregate
FROM
    "messages"
WHERE (EXISTS (
        SELECT
            *
        FROM
            "slack_users"
        WHERE
            "messages"."sender" = "slack_users"."slack_id"
            AND "slack_users"."id" = 'ABC123'));
SELECT
    count(*) AS aggregate
FROM
    "messages"
WHERE (EXISTS (
        SELECT
            *
        FROM
            "slack_users"
        WHERE
            "messages"."sender" = "slack_users"."slack_id"
            AND "slack_users"."id" = 'ABC123'));


Any ideas why it wouldn't be picking up the custom owner key in this situation?

Thanks!
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

select filter with belongsToMany
FilamentFFilament / ❓┊help
3y ago
Select filter with whereYear
FilamentFFilament / ❓┊help
3y ago
Select Filter with relation
FilamentFFilament / ❓┊help
3y ago
Custom Filter - Multi-Select on Pivot
FilamentFFilament / ❓┊help
15mo ago