deferFilters()
Filter::make('created_at') ->form([ DatePicker::make('created_from') ->label('Created from'), DatePicker::make('created_until') ->label('Created until'), ]) ->columns(2) ->columnSpan(2) ->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), ); }) ->indicateUsing(function (array $data): array { $indicators = []; if ($data['created_from'] ?? null) { $indicators[] = Indicator::make('Created from ' . Carbon::parse($data['created_from'])->toFormattedDateString()) ->removeField('created_from'); } if ($data['created_until'] ?? null) { $indicators[] = Indicator::make('Created until ' . Carbon::parse($data['created_until'])->toFormattedDateString()) ->removeField('created_until'); } return $indicators; })
config/app.php
php artisan filament:install --panels