|
12 | 12 | use Filament\Tables;
|
13 | 13 | use Filament\Tables\Columns\ImageColumn;
|
14 | 14 | use Filament\Tables\Columns\TextColumn;
|
| 15 | +use Filament\Tables\Filters\SelectFilter; |
15 | 16 | use Filament\Tables\Table;
|
16 | 17 | use Illuminate\Contracts\Support\Htmlable;
|
17 | 18 | use Illuminate\Database\Eloquent\Model;
|
@@ -103,6 +104,7 @@ public static function table(Table $table): Table
|
103 | 104 | TextColumn::make('id')
|
104 | 105 | ->label(__('filament-latex::filament-latex.column.id')),
|
105 | 106 | TextColumn::make('name')
|
| 107 | + ->searchable() |
106 | 108 | ->label(__('filament-latex::filament-latex.column.name')),
|
107 | 109 | ImageColumn::make('author_avatar')
|
108 | 110 | ->label(__('filament-latex::filament-latex.column.author_avatar'))
|
@@ -150,16 +152,33 @@ public static function table(Table $table): Table
|
150 | 152 | ->since(),
|
151 | 153 | ])
|
152 | 154 | ->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), |
154 | 173 | ])
|
155 | 174 | ->actions([
|
156 | 175 | Tables\Actions\ActionGroup::make([
|
157 | 176 | Tables\Actions\EditAction::make()
|
158 | 177 | ->color('warning'),
|
159 | 178 | Tables\Actions\DeleteAction::make()
|
160 | 179 | ->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(); |
163 | 182 | })
|
164 | 183 | ->requiresConfirmation()
|
165 | 184 | ->color('danger'),
|
|
0 commit comments