You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Employees.php 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. namespace App\Filament\Pages\Widgets\Employees\Tables;
  3. use App\Models\User;
  4. use Closure;
  5. use Exception;
  6. use Filament\Tables;
  7. use Filament\Widgets\TableWidget as PageWidget;
  8. use Illuminate\Contracts\Support\Htmlable;
  9. use Illuminate\Database\Eloquent\Builder;
  10. use Illuminate\Database\Eloquent\Relations\Relation;
  11. class Employees extends PageWidget
  12. {
  13. protected int|string|array $columnSpan = [
  14. 'md' => 2,
  15. 'xl' => 3,
  16. ];
  17. protected function getTableQuery(): Builder|Relation
  18. {
  19. return User::whereHas('employeeships');
  20. }
  21. protected function getTableHeading(): string|Htmlable|Closure|null
  22. {
  23. return null;
  24. }
  25. /**
  26. * @throws Exception
  27. */
  28. protected function getTableFilters(): array
  29. {
  30. return [
  31. Tables\Filters\SelectFilter::make('name')
  32. ->label('Company')
  33. ->relationship('companies', 'name', static fn (Builder $query) => $query->whereHas('users')),
  34. ];
  35. }
  36. protected function getTableColumns(): array
  37. {
  38. return [
  39. Tables\Columns\ViewColumn::make('name')
  40. ->view('filament.components.users.avatar-column')
  41. ->label('Name')
  42. ->sortable()
  43. ->searchable()
  44. ->grow(false),
  45. Tables\Columns\TextColumn::make('companies.name')
  46. ->label('Company')
  47. ->sortable()
  48. ->searchable()
  49. ->weight('semibold'),
  50. Tables\Columns\BadgeColumn::make('employeeships.role')
  51. ->label('Role')
  52. ->enum([
  53. 'admin' => 'Administrator',
  54. 'editor' => 'Editor',
  55. ])
  56. ->icons([
  57. 'heroicon-o-shield-check' => 'admin',
  58. 'heroicon-o-pencil' => 'editor',
  59. ])
  60. ->colors([
  61. 'primary' => 'admin',
  62. 'warning' => 'editor',
  63. ])
  64. ->sortable(),
  65. ];
  66. }
  67. }