Struggling with SelectFilter with relationship() and distinct status (Enum)

Hi guys ! I want to make a filter or the abacus_status in my users table but this status is in another table user_details, linked to the users via the details() relationship. What is wrong in my code ? ERROR : Object of class App\Enums\Users\AbacusStatusEnum could not be converted to string
Tables\Filters\SelectFilter::make('abacus_status')
->label(__('Status') . ' Abacus')
->multiple()
->relationship(
name: 'details',
titleAttribute: 'abacus_status',
modifyQueryUsing: fn(Builder $query) => $query->select('abacus_status')->groupBy('abacus_status')
)
->getOptionLabelFromRecordUsing(fn(UserDetail $record) => $record->abacus_status->getLabel())
->options(AbacusStatusEnum::class)
->preload(),
Tables\Filters\SelectFilter::make('abacus_status')
->label(__('Status') . ' Abacus')
->multiple()
->relationship(
name: 'details',
titleAttribute: 'abacus_status',
modifyQueryUsing: fn(Builder $query) => $query->select('abacus_status')->groupBy('abacus_status')
)
->getOptionLabelFromRecordUsing(fn(UserDetail $record) => $record->abacus_status->getLabel())
->options(AbacusStatusEnum::class)
->preload(),
1 Reply
Benjamin
BenjaminOP3mo ago
I foud similar issues (https://github.com/filamentphp/filament/issues/12948 + https://github.com/filamentphp/filament/issues/10086), and I finally used a custom filter :
Tables\Filters\Filter::make('abacus_status')
->indicateUsing(function (array $data): ?string {
if (!$status = $data['abacus_status']) {
return null;
}

$status = $status instanceof AbacusStatusEnum ? $status : AbacusStatusEnum::from($status);

return __('Status') . ' Abacus' . ': ' . $status->getLabel();
})
->form([
Forms\Components\Select::make('abacus_status')
->label(__('Status') . ' Abacus')
->options(AbacusStatusEnum::class),
])
->query(function (Builder $query, array $data): Builder {
if (!$status = $data['abacus_status']) {
return $query;
}

$status = $status instanceof AbacusStatusEnum ? $status : AbacusStatusEnum::from($status);

return $query->whereAbacusStatus($status);
}),
Tables\Filters\Filter::make('abacus_status')
->indicateUsing(function (array $data): ?string {
if (!$status = $data['abacus_status']) {
return null;
}

$status = $status instanceof AbacusStatusEnum ? $status : AbacusStatusEnum::from($status);

return __('Status') . ' Abacus' . ': ' . $status->getLabel();
})
->form([
Forms\Components\Select::make('abacus_status')
->label(__('Status') . ' Abacus')
->options(AbacusStatusEnum::class),
])
->query(function (Builder $query, array $data): Builder {
if (!$status = $data['abacus_status']) {
return $query;
}

$status = $status instanceof AbacusStatusEnum ? $status : AbacusStatusEnum::from($status);

return $query->whereAbacusStatus($status);
}),
GitHub
Table filter using a select on a relationship with a column based o...
Package filament/filament Package Version v3.2.82 Laravel Version v11.8.0 Livewire Version 3.5.0 PHP Version PHP 8.2.0 Problem description I get this error: Filament\Forms\Components\Select::isOpti...
GitHub
Issues · filamentphp/filament
A collection of beautiful full-stack components for Laravel. The perfect starting point for your next app. Using Livewire, Alpine.js and Tailwind CSS. - Issues · filamentphp/filament
Want results from more Discord servers?
Add your server