F
Filament16mo ago
ahinkle

Nullable DateTime Filter Value on Table Filter (v3)

Hi there, I have a table with three inputs: With Trashed Created At (from) Created At (to) The filters work but when I don't use the created_at filter, it defaults to null where it throws an exception: Could not parse 'null': Failed to parse time string (null) at position 0 (n): The timezone could not be found in the database The generated URL: admin/users?tableFilters[trashed][value]=1&tableFilters[Created%20At][created_from]=null&tableFilters[Created%20At][created_until]=null This works on v2 but doesn't work on v3. Any ideas? Filter:
$this->form([
DatePicker::make('created_from')->label('Created From'),
DatePicker::make('created_until')->label('Created Until'),
]);

$this->query(function (Builder $query, array $data): Builder {
return $query
->when(
$data['created_from'],
fn (Builder $query, $date): Builder => $query->whereDate('created_at', '>=', $date),
)
->when(
$data['created_until'],
fn (Builder $query, $date): Builder => $query->whereDate('created_at', '<=', $date),
);
});
$this->form([
DatePicker::make('created_from')->label('Created From'),
DatePicker::make('created_until')->label('Created Until'),
]);

$this->query(function (Builder $query, array $data): Builder {
return $query
->when(
$data['created_from'],
fn (Builder $query, $date): Builder => $query->whereDate('created_at', '>=', $date),
)
->when(
$data['created_until'],
fn (Builder $query, $date): Builder => $query->whereDate('created_at', '<=', $date),
);
});
3 Replies
ahinkle
ahinkleOP16mo ago
Removing the native datepicker fixes this issue (it might be a bug, not sure)
$this->form([
DatePicker::make('created_from')->label('Created From')->native(false),
DatePicker::make('created_until')->label('Created Until')->native(false),
]);
$this->form([
DatePicker::make('created_from')->label('Created From')->native(false),
DatePicker::make('created_until')->label('Created Until')->native(false),
]);
Kenneth Sese
Kenneth Sese16mo ago
This is a known issue that’s being worked on. https://github.com/filamentphp/filament/issues/7129
GitHub
Query string includes all available filters causing an error on ref...
Package filament/filament Package Version v3 Laravel Version v9.19 Livewire Version v3 PHP Version PHP 8.1 Problem description In v3 when you select a filter, the query string will then populate wi...
ahinkle
ahinkleOP16mo ago
Thanks!
Want results from more Discord servers?
Add your server