Table SelectFilter

I know I am missing something simple here, so just need a second set of eyes.

SelectFilter::make('status_id')
    ->label('Status')
    ->relationship('status', 'name'),
SelectFilter::make('type')
    ->label('Status Type')
    ->relationship('status', 'type'),
The type is just open or closed. Right now it doesnt filter by it and for some reason it lists 10 options in the select with half being open and half closed. Filtering by status name works fine.
Solution
I ended up doing
SelectFilter::make('type')
    ->label('Status Type')
    ->options([
        'open' => 'Open',
        'closed' => 'Closed',
    ])
    ->default(function () {
        if (request()->routeIs('outreach-activities')) {
            return 'open';
        }
    })
    ->query(
        function ($query, $data) {
            $selectedStatus = $data['value'] ?? null;

            $query->when($selectedStatus, function ($q) use ($selectedStatus) {
                $q->whereHas('status', function ($subQuery) use ($selectedStatus) {
                    $subQuery->where('type', $selectedStatus);
                });
            });
        }
    ),
Was this page helpful?