refresh select filter that uses an attribute

I have a SelectFilter which filters upon status as follows:
SelectFilter::make('status')
->label('Status')
->options([
__('mesco.produced') => __('mesco.produced'),
__('mesco.partially produced') => __('mesco.partially produced'),
__('mesco.planned') => __('mesco.planned'),
__('mesco.new') => __('mesco.new'),
])
->query(function ($query) {
$status = Request::get('tableFilters')['status']['value'] ?? null;
if ($status) {
return $query->withStatus($status);
}
})
SelectFilter::make('status')
->label('Status')
->options([
__('mesco.produced') => __('mesco.produced'),
__('mesco.partially produced') => __('mesco.partially produced'),
__('mesco.planned') => __('mesco.planned'),
__('mesco.new') => __('mesco.new'),
])
->query(function ($query) {
$status = Request::get('tableFilters')['status']['value'] ?? null;
if ($status) {
return $query->withStatus($status);
}
})
The status which we are checking is not in the DB, it is an attribute, which is why I alter the query. In my model:
public function getStatusAttribute(): string
{
// returns calculated status
}

public function scopeWithStatus($query, $status)
{
// alters query
}
public function getStatusAttribute(): string
{
// returns calculated status
}

public function scopeWithStatus($query, $status)
{
// alters query
}
The filter works, but only after I refresh the page. Upon applying the filter, everything shows, once I refresh, the filtered records are shown. How can I tell filament to refresh the table data again, or even simply to refresh/reload the entire page, opnce the filter has been applied?
Solution:
maybe you can inject array $data? You can also use custom filter forms...
Jump to solution
2 Replies
Solution
LeandroFerreira
LeandroFerreira2mo ago
maybe you can inject array $data? You can also use custom filter forms
delboy1978uk
delboy1978ukOP2mo ago
@Leandro Ferreira that worked, thanks so much, I was wondering how to get the value, so I was just hackily grabbing it from the request!

Did you find this page helpful?