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.

DepartmentResource.php 3.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. namespace App\Filament\Company\Resources\Core;
  3. use App\Filament\Company\Resources\Core\DepartmentResource\Pages;
  4. use App\Models\Core\Department;
  5. use Filament\Forms\Form;
  6. use Filament\Resources\Resource;
  7. use Filament\Tables\Table;
  8. use Filament\{Forms, Tables};
  9. class DepartmentResource extends Resource
  10. {
  11. protected static ?string $model = Department::class;
  12. protected static ?string $navigationIcon = 'heroicon-o-square-3-stack-3d';
  13. protected static ?string $navigationGroup = 'HR';
  14. protected static ?string $slug = 'hr/departments';
  15. public static function form(Form $form): Form
  16. {
  17. return $form
  18. ->schema([
  19. Forms\Components\Section::make('General')
  20. ->schema([
  21. Forms\Components\TextInput::make('name')
  22. ->autofocus()
  23. ->required()
  24. ->maxLength(100),
  25. Forms\Components\Select::make('manager_id')
  26. ->label('Manager')
  27. ->relationship('manager', 'name')
  28. ->searchable()
  29. ->preload()
  30. ->placeholder('Select a manager')
  31. ->nullable(),
  32. Forms\Components\Group::make()
  33. ->schema([
  34. Forms\Components\Select::make('parent_id')
  35. ->label('Parent Department')
  36. ->relationship('parent', 'name')
  37. ->preload()
  38. ->searchable()
  39. ->nullable(),
  40. Forms\Components\Textarea::make('description')
  41. ->label('Description')
  42. ->autosize()
  43. ->nullable(),
  44. ])->columns(1),
  45. ])->columns(),
  46. ]);
  47. }
  48. public static function table(Table $table): Table
  49. {
  50. return $table
  51. ->columns([
  52. Tables\Columns\TextColumn::make('name')
  53. ->weight('semibold')
  54. ->searchable()
  55. ->sortable(),
  56. Tables\Columns\TextColumn::make('manager.name')
  57. ->label('Manager')
  58. ->searchable()
  59. ->sortable(),
  60. ])
  61. ->filters([
  62. //
  63. ])
  64. ->actions([
  65. Tables\Actions\EditAction::make(),
  66. ])
  67. ->bulkActions([
  68. Tables\Actions\BulkActionGroup::make([
  69. Tables\Actions\DeleteBulkAction::make(),
  70. ]),
  71. ]);
  72. }
  73. public static function getRelations(): array
  74. {
  75. return [
  76. //
  77. ];
  78. }
  79. public static function getPages(): array
  80. {
  81. return [
  82. 'index' => Pages\ListDepartments::route('/'),
  83. 'create' => Pages\CreateDepartment::route('/create'),
  84. 'edit' => Pages\EditDepartment::route('/{record}/edit'),
  85. ];
  86. }
  87. }