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

philipbaginski's avatar

Laravel Nova filter with pluck

Hi! In table Players I have a column 'country_id' which is related to table Countries. I made filter CountryFilter with cod:

public function apply(Request $request, $query, $value) { return $query->where('country_id', $value); }

, and options:

public function options(Request $request) { $models = \App\Country::all(); return $models->pluck('id', 'name'); }

The problem: Countries are doubled or tripled (some of them have different 'code' which is importent to mark Player) and on the select list of filter doubled countries are not displayed moe than one time, e.g. Germany are with three different 'codes'. On the select list I can see Germany only one time. If I change ->pluck('id', 'name') into ->pluck('id', code'); - I can se all records, but as codes what is difficult to recognize which country it is.

Is there any possibility to show the list with all names?

0 likes
2 replies
saamretep's avatar

You should try:

public function options(Request $request)
{
    return \App\Country::pluck('id', 'name');
}

Please or to participate in this conversation.