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

Cushty's avatar
Level 4

Services and filament tables livewire component

Hi, I have a service that has a load of options, I've queried the options in a select filter, but I am getting:

An attempt was made to evaluate a closure for [Filament\Tables\Filters\SelectFilter], but [$value] was unresolvable. Do I need to do something else as it's a livewire component? Thanks

<?php

namespace App\Services;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Facades\Log;

class PricingFilterService
{
    public static function getOptions(): array
    {
        return [
            'under_40' => 'Under 40',
            '40_60' => '40 - 60',
            '60_80' => '60 - 80',
            '80_100' => '80 - 100',
            '100_120' => '100 - 120',
            '120_140' => '120 - 140',
            '140_160' => '140 - 160',
            '160_180' => '160 - 180',
            '180_200' => '180 - 200',
            '200_plus' => '200+',
            
        ];
    }

    public static function applyQuery(Builder $query, $value, $column): Builder
    {
        $query->whereNotNull($column);
        return match ($value) {
           'under_40' => $query->where($column, '<', 40),
            '40_60' => $query->whereBetween($column, [40, 60]),
            '60_80' => $query->whereBetween($column, [60, 80]),
            '80_100' => $query->whereBetween($column, [80, 100]),
            '100_120' => $query->whereBetween($column, [100, 120]),
            '120_140' => $query->whereBetween($column, [120, 140]),
            '140_160' => $query->whereBetween($column, [140, 160]),
            '160_180' => $query->whereBetween($column, [160, 180]),
            '180_200' => $query->whereBetween($column, [180, 200]),
            '200_plus' => $query->where($column, '>', 200),
default => $query,
        };
    }
}
SelectFilter::make('sport_pricing')
                    ->label('Individual pricing')
                    ->options(PricingFilterService::getOptions())
                    ->query(function (Builder $query, $value) {
                        return PricingFilterService::applyQuery($query, $value, 'sport_pricing');
                    }),

0 likes
3 replies
prasadchinwal5's avatar

I am not a 100% on this but I believe you can use the query method only when you provide an eloquent model to the options method.

One way would be to check the type of the $query in the query method.

SelectFilter::make('sport_pricing')
->label('Individual pricing')
->options(PricingFilterService::getOptions())
->query(function (Builder $query, $value) {
  dd($query); 
  return PricingFilterService::applyQuery($query, $value, 'sport_pricing');
}),
Cushty's avatar
Level 4

@prasadchinwal5 Thanks for the reply, if I add the dd it does not show I only get the error message An attempt was made to evaluate a closure for [Filament\Tables\Filters\SelectFilter], but [$value] was unresolvable.

What's really weird is if I leave off the query entirely and just use an option depending on the number in the form it actually shows search results, so strange.

prasadchinwal5's avatar

@cushty Kind of figured out the reason for the error. The reason for the error is because when the page is rendered the $value and $column values are not present hence you get an error

An attempt was made to evaluate a closure for [Filament\Tables\Filters\SelectFilter], but [$value] was unresolvable.

What you actually want to do it use a Custom Filter. This way you can grab the data selected from the input and run the query.

Filter::make('sport_pricing')
                        ->form([
                            Select::make('selected_sport_pricing')
                                ->label('Individual pricing')
                                ->options(House::options()),
                        ])
                        ->query(function (Builder $query, $data): Builder {
                            $query->whereNotNull('sport_pricing');
                            return match ($data['selected_sport_pricing']) {
                                'under_40' => $query->where('sport_pricing', '<', 40),
                                '40_60' => $query->whereBetween('sport_pricing', [40, 60]),
                                '60_80' => $query->whereBetween('sport_pricing', [60, 80]),
                                '80_100' => $query->whereBetween('sport_pricing', [80, 100]),
                                '100_120' => $query->whereBetween('sport_pricing', [100, 120]),
                                '120_140' => $query->whereBetween('sport_pricing', [120, 140]),
                                '140_160' => $query->whereBetween('sport_pricing', [140, 160]),
                                '160_180' => $query->whereBetween('sport_pricing', [160, 180]),
                                '180_200' => $query->whereBetween('sport_pricing', [180, 200]),
                                '200_plus' => $query->where('sport_pricing', '>', 200),
                                default => $query,
                            };
                        })

Please or to participate in this conversation.