|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace App\Filament\Resources\Feedback\Tables; |
| 6 | + |
| 7 | +use App\Models\County; |
| 8 | +use App\Models\Feedback; |
| 9 | +use Filament\Actions\DeleteAction; |
| 10 | +use Filament\Actions\EditAction; |
| 11 | +use Filament\Actions\ViewAction; |
| 12 | +use Filament\Tables\Columns\TextColumn; |
| 13 | +use Filament\Tables\Filters\SelectFilter; |
| 14 | +use Filament\Tables\Table; |
| 15 | +use Illuminate\Database\Eloquent\Builder; |
| 16 | +use Malzariey\FilamentDaterangepickerFilter\Filters\DateRangeFilter; |
| 17 | + |
| 18 | +class FeedbackTable |
| 19 | +{ |
| 20 | + public static function configure(Table $table): Table |
| 21 | + { |
| 22 | + return $table |
| 23 | + ->modifyQueryUsing(fn (Builder $query) => $query->with(['user', 'category', 'subcategory', 'county', 'city'])) |
| 24 | + ->columns([ |
| 25 | + TextColumn::make('id') |
| 26 | + ->label(__('field.id')) |
| 27 | + ->prefix('#') |
| 28 | + ->sortable() |
| 29 | + ->searchable() |
| 30 | + ->toggleable(), |
| 31 | + |
| 32 | + TextColumn::make('user.full_name') |
| 33 | + ->label(__('field.user')) |
| 34 | + ->toggleable(fn (TextColumn $column) => ! $column->isHidden()) |
| 35 | + ->description(fn (Feedback $record): string => $record->user->role->getLabel()) |
| 36 | + ->hidden(fn (): bool => auth()->user()->isNurseOrMediator()), |
| 37 | + |
| 38 | + TextColumn::make('category.name') |
| 39 | + ->label(__('field.category')) |
| 40 | + ->limit() |
| 41 | + ->sortable() |
| 42 | + ->toggleable(), |
| 43 | + |
| 44 | + TextColumn::make('subcategory.name') |
| 45 | + ->label(__('field.subcategory')) |
| 46 | + ->limit() |
| 47 | + ->toggleable(), |
| 48 | + |
| 49 | + TextColumn::make('county.name') |
| 50 | + ->label(__('field.county')) |
| 51 | + ->hidden(fn (): bool => auth()->user()->isNurseOrMediator()) |
| 52 | + ->toggleable(), |
| 53 | + |
| 54 | + TextColumn::make('city.name') |
| 55 | + ->label(__('field.city')) |
| 56 | + ->toggleable(), |
| 57 | + |
| 58 | + TextColumn::make('created_at') |
| 59 | + ->label(__('field.date')) |
| 60 | + ->size('sm') |
| 61 | + ->date() |
| 62 | + ->sortable() |
| 63 | + ->toggleable(), |
| 64 | + ]) |
| 65 | + ->filters([ |
| 66 | + SelectFilter::make('category') |
| 67 | + ->label(__('field.category')) |
| 68 | + ->relationship('category', 'name'), |
| 69 | + |
| 70 | + SelectFilter::make('subcategory') |
| 71 | + ->label(__('field.subcategory')) |
| 72 | + ->relationship('subcategory', 'name'), |
| 73 | + |
| 74 | + SelectFilter::make('county_id') |
| 75 | + ->label(__('field.county')) |
| 76 | + ->options(County::cachedList()) |
| 77 | + ->visible(fn (): bool => auth()->user()->isAdmin()), |
| 78 | + |
| 79 | + SelectFilter::make('user') |
| 80 | + ->label(__('field.user')) |
| 81 | + ->relationship('user', 'full_name', fn (Builder $query) => $query->onlyNursesAndMediators()) |
| 82 | + ->multiple() |
| 83 | + ->hidden(fn (): bool => auth()->user()->isNurseOrMediator()), |
| 84 | + |
| 85 | + DateRangeFilter::make('created_at') |
| 86 | + ->label(__('field.date')), |
| 87 | + ]) |
| 88 | + ->recordActions([ |
| 89 | + ViewAction::make() |
| 90 | + ->iconButton(), |
| 91 | + |
| 92 | + EditAction::make() |
| 93 | + ->iconButton(), |
| 94 | + |
| 95 | + DeleteAction::make() |
| 96 | + ->iconButton(), |
| 97 | + ]) |
| 98 | + ->defaultSort('id', 'desc'); |
| 99 | + } |
| 100 | +} |
0 commit comments