please how to modify the Filament Resource for adding/editing as follows:
i need Unis listing in CheckboxList to be split into columns by Unit->department_id. Currently, all the units are listed together, but for the sake of overview, I want to have many of them in columns so that each column contains only units with the same department_id.
my code :
<?php
namespace AppFilamentResources;
use FilamentForms;
use FilamentResourcesResource;
use AppFilamentResourcesClientResourcePages;
use FilamentTables;
use FilamentTablesTable;
use FilamentFormsComponentsCheckboxList;
use FilamentFormsComponentsFieldset;
use FilamentFormsComponentsGrid;
use AppModelsClient;
use CarbonCarbon;
use AppModelsDepartment;
use AppModelsUnit;
class ClientResource extends Resource
{
protected static ?string $model = Client::class;
protected static ?string $navigationIcon = 'heroicon-o-briefcase';
public static function form(FormsForm $form): FormsForm
{
return $form
->schema([
Fieldset::make('Base informations')
->schema([
FormsComponentsTextInput::make('client_name')
->required()
->maxLength(255)
->label('Name'),
FormsComponentsSelect::make('department_id')
->label('Client zone')
->options(Department::all()->pluck('name', 'id'))
->reactive()
->required(),
FormsComponentsDatePicker::make('valid_from')
->required()
->default(now())
->label('Valid From'),
FormsComponentsDatePicker::make('valid_to')
->required()
->default(Carbon::now()->addYear())
->label('Valid To'),
FormsComponentsToggle::make('enabled')
->label('Enabled')
->default(true)
->inline(false),
])
->columns([
'sm' => 2,
'md' => 2,
'lg' => 3,
'xl' => 4,
'2xl' => 5,
]),
Fieldset::make('Units by Department')
->schema([
CheckboxList::make('units')
->label('Units')
->options(
Unit::all()
->sortBy('department_id')
->mapWithKeys(function ($unit) {
return [$unit->id => $unit->name . ' (' . $unit->department->name . ')'];
})
->toArray()
)
->columns(3)
->searchable()
->bulkToggleable(),
])
]);
}
public static function table(TablesTable $table): TablesTable
{
return $table
->columns([
TablesColumnsTextColumn::make('client_name')
->label('Name'),
TablesColumnsTextColumn::make('department.name')
->label('Client zone'),
TablesColumnsTextColumn::make('valid_from')
->date()
->label('Valid From'),
TablesColumnsTextColumn::make('valid_to')
->date()
->label('Valid To'),
TablesColumnsTagsColumn::make('units.name')
->label('Units'),
TablesColumnsTextColumn::make('created_at')
->dateTime()
->label('Created At'),
TablesColumnsTextColumn::make('updated_at')
->dateTime()
->label('Updated At'),
])
->filters([
// Možnosti filtrov, ak sú potrebné
])
->actions([
TablesActionsEditAction::make(),
TablesActionsDeleteAction::make(),
])
->bulkActions([
TablesActionsBulkActionGroup::make([
TablesActionsDeleteBulkAction::make(),
]),
]);
}
public static function getRelations(): array
{
return [
// Definujte vzťahy, ak je to potrebné
];
}
public static function getPages(): array
{
return [
'index' => PagesListClients::route('/'),
'create' => PagesCreateClient::route('/create'),
'edit' => PagesEditClient::route('/{record}/edit'),
];
}
}
Many thanks for your help guys