RamboRoland
RamboRoland
FFilament
Created by RamboRoland on 10/28/2023 in #❓┊help
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
FFilament
Created by RamboRoland on 10/28/2023 in #❓┊help
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
FFilament
Created by RamboRoland on 10/26/2023 in #❓┊help
Update Repeater sort index visibly when cloneable is used
When a repeater has cloneable. I don't manage to get a updated sort index. I show the sort value for the user when it’s collapsed because in my case it represents a day in a schedule. Filament: 3.0.84
1 replies