Skip to content

Commit

Permalink
activities filter
Browse files Browse the repository at this point in the history
  • Loading branch information
fzldn committed Sep 17, 2024
1 parent e423003 commit dd6429a
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions app/Filament/Resources/ActivityResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Filament\Resources\ActivityResource\Pages;
use App\Filament\Resources\ActivityResource\RelationManagers;
use App\Models\Activity;
use App\Models\User;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Resources\Resource;
Expand Down Expand Up @@ -32,8 +33,6 @@ public static function getNavigationGroup(): ?string
public static function table(Table $table): Table
{
return $table
->heading(__('Activity Logs'))
->description(__('A log of all activity in the system.'))
->columns([
Tables\Columns\Layout\Split::make([
Tables\Columns\TextColumn::make('description')->html(),
Expand All @@ -46,8 +45,31 @@ public static function table(Table $table): Table
]),
])
->filters([
//
]);
Tables\Filters\Filter::make('from')
->form([Forms\Components\DatePicker::make('from')])
->query(function (Builder $query, array $data): Builder {
return $query
->when(
$data['from'],
fn(Builder $query, $date): Builder => $query->whereDate('created_at', '>=', $date),
);
}),
Tables\Filters\Filter::make('to')
->form([Forms\Components\DatePicker::make('to')])
->query(function (Builder $query, array $data): Builder {
return $query
->when(
$data['to'],
fn(Builder $query, $date): Builder => $query->whereDate('created_at', '<=', $date),
);
}),
Tables\Filters\SelectFilter::make('causer_id')
->label(__('Causer'))
->options(
User::orderBy('name')->pluck('name', 'id')
)
->searchable(),
], layout: Tables\Enums\FiltersLayout::AboveContent);
}

public static function getPages(): array
Expand Down

0 comments on commit dd6429a

Please sign in to comment.