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

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