12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- <?php
-
- namespace App\Filament\Pages\Widgets\Employees\Tables;
-
- use App\Models\User;
- use Closure;
- use Exception;
- use Filament\Tables;
- use Filament\Widgets\TableWidget as PageWidget;
- use Illuminate\Contracts\Support\Htmlable;
- use Illuminate\Database\Eloquent\Builder;
- use Illuminate\Database\Eloquent\Relations\Relation;
-
- class Employees extends PageWidget
- {
- protected int | string | array $columnSpan = 'full';
-
- protected static ?int $sort = 2;
-
- protected function getTableQuery(): Builder|Relation
- {
- return User::whereHas('employeeships');
- }
-
- protected function getTableHeading(): string|Htmlable|Closure|null
- {
- return null;
- }
-
- /**
- * @throws Exception
- */
- protected function getTableFilters(): array
- {
- return [
- Tables\Filters\SelectFilter::make('name')
- ->label('Company')
- ->searchable()
- ->relationship('companies', 'name', static fn (Builder $query) => $query->whereHas('users')),
- ];
- }
-
- protected function getTableColumns(): array
- {
- return [
- Tables\Columns\ViewColumn::make('name')
- ->view('filament.components.users.avatar-column')
- ->label('Name')
- ->sortable()
- ->searchable()
- ->grow(false),
- Tables\Columns\TextColumn::make('companies.name')
- ->label('Company')
- ->sortable()
- ->searchable(),
- Tables\Columns\BadgeColumn::make('employeeships.role')
- ->label('Role')
- ->enum([
- 'admin' => 'Administrator',
- 'editor' => 'Editor',
- ])
- ->icons([
- 'heroicon-o-shield-check' => 'admin',
- 'heroicon-o-pencil' => 'editor',
- ])
- ->colors([
- 'primary' => 'admin',
- 'warning' => 'editor',
- ])
- ->sortable(),
- ];
- }
- }
|