© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•3y ago•
2 replies
nn

Filtering options in RelationManager

I have four Resources:
GameMatch, Event, Player, Team
I have a RelationManager inside the GameMatch resource, for Events. It's successfully working.
I have a Select for player_id, when creating a new event on that modal, but it shows all the players of the database. My wish would be to show only the players with a team_id equal to home_team_id or away_team_id from the GameMatch.
The code I conjured up is the following:
                Select::make('player_id')
                    ->relationship(
                        name: 'player',
                        titleAttribute: 'team_id',
                        modifyQueryUsing: function (Builder $query){
                            $home_id = GameMatch::query()->pluck('home_team_id');
                            return $query->where('team_id',$home_id);
                        }
                    )
                    ->getOptionLabelFromRecordUsing(function (Player $record) {
                        $team = Team::find($record->team_id);
                        return "{$record->name} : {$team->name}";
                    })
                    ->preload()
                    ->searchable()
                    ->required(),
                Select::make('player_id')
                    ->relationship(
                        name: 'player',
                        titleAttribute: 'team_id',
                        modifyQueryUsing: function (Builder $query){
                            $home_id = GameMatch::query()->pluck('home_team_id');
                            return $query->where('team_id',$home_id);
                        }
                    )
                    ->getOptionLabelFromRecordUsing(function (Player $record) {
                        $team = Team::find($record->team_id);
                        return "{$record->name} : {$team->name}";
                    })
                    ->preload()
                    ->searchable()
                    ->required(),

However I'm receiving a Invalid parameter number, although the query that's displayed on that dialog produces the right results when querying the database. I'm sure I'm doing something wrong but can't figure out what. Thanks for any help.
Solution
In the end, I figured it out. GameMatch was getting me a collection, and not a contextualized GameMatch. Got there doing it like this:

                        modifyQueryUsing: function (Builder $query){
                            return $query->where('team_id',$this->ownerRecord->home_team_id)->orWhere('team_id', $this->ownerRecord->away_team_id);
                        }
                        modifyQueryUsing: function (Builder $query){
                            return $query->where('team_id',$this->ownerRecord->home_team_id)->orWhere('team_id', $this->ownerRecord->away_team_id);
                        }
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 Enum Options
FilamentFFilament / ❓┊help
8mo ago
Modify Label Options in RelationManager attach action
FilamentFFilament / ❓┊help
2y ago
Filtering select options on-fly
FilamentFFilament / ❓┊help
2y ago
AttachAction in relationManager
FilamentFFilament / ❓┊help
14mo ago