SelectFilter doesn not work like I want

Hello I have a select filter
Tables\Filters\SelectFilter::make('status_filter')
->options(JobStatusEnum::asSelectArray())
->modifyQueryUsing(function (mixed $state, Builder $query): Builder {
return $query->where('status', $state);
}),
Tables\Filters\SelectFilter::make('status_filter')
->options(JobStatusEnum::asSelectArray())
->modifyQueryUsing(function (mixed $state, Builder $query): Builder {
return $query->where('status', $state);
}),
And it's work, but when I not have any selected option I dont have a any record in table. How I can fix them?
Solution:
I think you can use $query->when(..) like this example
Jump to solution
3 Replies
__Dementor
__DementorOP22h ago
JobStatusEnum
final class JobStatusEnum extends Enum
{
/** @var string */
const New = 'new';

/** @var string */
const Realization = 'realization';

/** @var string */
const Finished = 'finished';

/** @var string */
const Payment = 'payment';

/** @var string */
const Rejected = 'rejected';

/** @var string */
const Cancelled = 'cancelled';
}
final class JobStatusEnum extends Enum
{
/** @var string */
const New = 'new';

/** @var string */
const Realization = 'realization';

/** @var string */
const Finished = 'finished';

/** @var string */
const Payment = 'payment';

/** @var string */
const Rejected = 'rejected';

/** @var string */
const Cancelled = 'cancelled';
}
Solution
LeandroFerreira
LeandroFerreira22h ago
I think you can use $query->when(..) like this example
__Dementor
__DementorOP22h ago
Yeah Its works ❤️

Did you find this page helpful?