您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

Employees.php 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 = 'full';
  14. protected static ?int $sort = 2;
  15. protected function getTableQuery(): Builder|Relation
  16. {
  17. return User::whereHas('employeeships');
  18. }
  19. protected function getTableHeading(): string|Htmlable|Closure|null
  20. {
  21. return null;
  22. }
  23. /**
  24. * @throws Exception
  25. */
  26. protected function getTableFilters(): array
  27. {
  28. return [
  29. Tables\Filters\SelectFilter::make('name')
  30. ->label('Company')
  31. ->searchable()
  32. ->relationship('companies', 'name', static fn (Builder $query) => $query->whereHas('users')),
  33. ];
  34. }
  35. protected function getTableColumns(): array
  36. {
  37. return [
  38. Tables\Columns\ViewColumn::make('name')
  39. ->view('filament.components.users.avatar-column')
  40. ->label('Name')
  41. ->sortable()
  42. ->searchable()
  43. ->grow(false),
  44. Tables\Columns\TextColumn::make('companies.name')
  45. ->label('Company')
  46. ->sortable()
  47. ->searchable(),
  48. Tables\Columns\BadgeColumn::make('employeeships.role')
  49. ->label('Role')
  50. ->enum([
  51. 'admin' => 'Administrator',
  52. 'editor' => 'Editor',
  53. ])
  54. ->icons([
  55. 'heroicon-o-shield-check' => 'admin',
  56. 'heroicon-o-pencil' => 'editor',
  57. ])
  58. ->colors([
  59. 'primary' => 'admin',
  60. 'warning' => 'editor',
  61. ])
  62. ->sortable(),
  63. ];
  64. }
  65. }