FilamentF
Filament17mo ago
Cushty

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? I have more price options but hit limit of discord 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',
            
        ];
    }

    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]),
            default => $query,
        };
    }
}

SelectFilter::make('sport_pricing')
                    ->label('Individual pricing')
                    ->options(PricingFilterService::getOptions())
                    ->query(function (Builder $query, $value) {
                        return PricingFilterService::applyQuery($query, $value, 'sport_pricing');
                    }),
Was this page helpful?