Skip to content

Commit

Permalink
filter indicateUsing
Browse files Browse the repository at this point in the history
  • Loading branch information
fzldn committed Sep 19, 2024
1 parent dd6429a commit 1e6b127
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions app/Filament/Resources/ActivityResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ public static function table(Table $table): Table
]),
])
->filters([
Tables\Filters\SelectFilter::make('causer_id')
->label(__('Causer'))
->options(
User::orderBy('name')->pluck('name', 'id')
)
->searchable(),
Tables\Filters\Filter::make('from')
->form([Forms\Components\DatePicker::make('from')])
->query(function (Builder $query, array $data): Builder {
Expand All @@ -53,6 +59,13 @@ public static function table(Table $table): Table
$data['from'],
fn(Builder $query, $date): Builder => $query->whereDate('created_at', '>=', $date),
);
})
->indicateUsing(function ($data) {
if (! $data['from']) {
return null;
}

return __('From: :date', ['date' => $data['from']]);
}),
Tables\Filters\Filter::make('to')
->form([Forms\Components\DatePicker::make('to')])
Expand All @@ -62,13 +75,14 @@ public static function table(Table $table): Table
$data['to'],
fn(Builder $query, $date): Builder => $query->whereDate('created_at', '<=', $date),
);
})
->indicateUsing(function ($data) {
if (! $data['to']) {
return null;
}

return __('To: :date', ['date' => $data['to']]);
}),
Tables\Filters\SelectFilter::make('causer_id')
->label(__('Causer'))
->options(
User::orderBy('name')->pluck('name', 'id')
)
->searchable(),
], layout: Tables\Enums\FiltersLayout::AboveContent);
}

Expand Down

0 comments on commit 1e6b127

Please sign in to comment.