RamboRoland
Preload Resource data for form
Is it possible to preload data for a resource? I have 2 Repeaters nested and that makes 14 queries with 1 item. Can i preload?
Filament: 3.0.86
$form
->schema([
Forms\Components\TextInput::make('name')
->columnSpan(3),
Forms\Components\Repeater::make('days')
->relationship()
->label('Days')
->orderColumn('day')
->schema([
Forms\Components\Repeater::make('nutrients')
->label('Nutrients')
->relationship()
->schema([
Forms\Components\TextInput::make('parts'),
Forms\Components\Select::make('nutrient_id')
->options($nutrients->pluck('name', 'id'))
]),
Forms\Components\Repeater::make('oncePerDayNutrients')
->relationship()
->schema([
Forms\Components\TextInput::make('ml'),
Forms\Components\Select::make('nutrient_id')
->label('Nutrient')
->options($nutrients->pluck('name', 'id'))
]),
Forms\Components\Repeater::make('lights')
->relationship()
->schema([
Forms\Components\Select::make('light_id')
->label('Light')
->options($lights->pluck('name', 'id'))
])
])
]);
$form
->schema([
Forms\Components\TextInput::make('name')
->columnSpan(3),
Forms\Components\Repeater::make('days')
->relationship()
->label('Days')
->orderColumn('day')
->schema([
Forms\Components\Repeater::make('nutrients')
->label('Nutrients')
->relationship()
->schema([
Forms\Components\TextInput::make('parts'),
Forms\Components\Select::make('nutrient_id')
->options($nutrients->pluck('name', 'id'))
]),
Forms\Components\Repeater::make('oncePerDayNutrients')
->relationship()
->schema([
Forms\Components\TextInput::make('ml'),
Forms\Components\Select::make('nutrient_id')
->label('Nutrient')
->options($nutrients->pluck('name', 'id'))
]),
Forms\Components\Repeater::make('lights')
->relationship()
->schema([
Forms\Components\Select::make('light_id')
->label('Light')
->options($lights->pluck('name', 'id'))
])
])
]);
2 replies
Repeater reordering violates unique constraint
Hi, I try to reorder my items and SQL throws violates unique constraint. When i clone a item it works but not when i reorder.
Filament: 3.0.86
My code:
Forms\Components\Repeater::make('days')
->relationship()
->label('Days')
->cloneable()
->collapsible()
->collapsed()
->orderColumn('day')
->reorderableWithButtons()
->itemLabel(function (array $state) {
$labels = [];
if (isset($state['day']) && $state['day']) {
$labels[] = 'Day ' . $state['day'];
}
if (isset($state['nutrients']) && count($state['nutrients'])) {
$labels[] = "N" . count($state['nutrients']);
}
if (isset($state['oncePerDayNutrients']) && count($state['oncePerDayNutrients'])) {
$labels[] = "O" . count($state['oncePerDayNutrients']);
}
if (isset($state['lights']) && count($state['lights'])) {
$labels[] = "L" . count($state['lights']);
}
return count($labels) ? implode(' | ', $labels) : null;
})
Forms\Components\Repeater::make('days')
->relationship()
->label('Days')
->cloneable()
->collapsible()
->collapsed()
->orderColumn('day')
->reorderableWithButtons()
->itemLabel(function (array $state) {
$labels = [];
if (isset($state['day']) && $state['day']) {
$labels[] = 'Day ' . $state['day'];
}
if (isset($state['nutrients']) && count($state['nutrients'])) {
$labels[] = "N" . count($state['nutrients']);
}
if (isset($state['oncePerDayNutrients']) && count($state['oncePerDayNutrients'])) {
$labels[] = "O" . count($state['oncePerDayNutrients']);
}
if (isset($state['lights']) && count($state['lights'])) {
$labels[] = "L" . count($state['lights']);
}
return count($labels) ? implode(' | ', $labels) : null;
})
3 replies