Skip to content

Commit 6f9c800

Browse files
Merge pull request #61 from thethunderturner/feature/table-filters
Feature: Table filters
2 parents e6badcd + 30699b7 commit 6f9c800

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

src/Resources/FilamentLatexResource.php

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Filament\Tables;
1313
use Filament\Tables\Columns\ImageColumn;
1414
use Filament\Tables\Columns\TextColumn;
15+
use Filament\Tables\Filters\SelectFilter;
1516
use Filament\Tables\Table;
1617
use Illuminate\Contracts\Support\Htmlable;
1718
use Illuminate\Database\Eloquent\Model;
@@ -103,6 +104,7 @@ public static function table(Table $table): Table
103104
TextColumn::make('id')
104105
->label(__('filament-latex::filament-latex.column.id')),
105106
TextColumn::make('name')
107+
->searchable()
106108
->label(__('filament-latex::filament-latex.column.name')),
107109
ImageColumn::make('author_avatar')
108110
->label(__('filament-latex::filament-latex.column.author_avatar'))
@@ -150,16 +152,33 @@ public static function table(Table $table): Table
150152
->since(),
151153
])
152154
->filters([
153-
//
155+
SelectFilter::make('author_id')
156+
->label(__('filament-latex::filament-latex.column.author.name'))
157+
->default(fn () => Auth::id())
158+
->options(fn () => $userModel::all()->pluck('name', 'id'))
159+
->native(false),
160+
SelectFilter::make('collaborators_id')
161+
->label(__('filament-latex::filament-latex.column.collaborators'))
162+
->options(fn () => $userModel::all()->pluck('name', 'id'))
163+
->query(function ($query, $data) {
164+
if (! empty($data)) {
165+
// Apply the filter for JSON column
166+
foreach ($data as $id) {
167+
$query->whereJsonContains('collaborators_id', $id);
168+
}
169+
}
170+
})
171+
->multiple()
172+
->native(false),
154173
])
155174
->actions([
156175
Tables\Actions\ActionGroup::make([
157176
Tables\Actions\EditAction::make()
158177
->color('warning'),
159178
Tables\Actions\DeleteAction::make()
160179
->visible(function ($record) {
161-
// In the future, only the creator can delete the record
162-
return true;
180+
// Only the creator can delete the record
181+
return $record->author_id === Auth::id();
163182
})
164183
->requiresConfirmation()
165184
->color('danger'),

0 commit comments

Comments
 (0)