Repeater::make('cartonTransactions')
->relationship() // Relationship is set up correctly
->schema([
Select::make('item')
->label('Item')
->options(Item::pluck('name', 'id'))
->required(),
TextInput::make('quantity')
->numeric()
->minValue(1)
->required(),
])
->mutateRelationshipDataBeforeCreateUsing(function (array $data): array {
// I want to create multiple records based on the quantity field.
$quantity = (int) $data['quantity'];
$item = $data['item'];
$records = [];
for ($i = 0; $i < $quantity; $i++) {
$records[] = [
'item' => $item,
];
}
// Returning an array of arrays instead of a single associative array.
return $records;
});
Repeater::make('cartonTransactions')
->relationship() // Relationship is set up correctly
->schema([
Select::make('item')
->label('Item')
->options(Item::pluck('name', 'id'))
->required(),
TextInput::make('quantity')
->numeric()
->minValue(1)
->required(),
])
->mutateRelationshipDataBeforeCreateUsing(function (array $data): array {
// I want to create multiple records based on the quantity field.
$quantity = (int) $data['quantity'];
$item = $data['item'];
$records = [];
for ($i = 0; $i < $quantity; $i++) {
$records[] = [
'item' => $item,
];
}
// Returning an array of arrays instead of a single associative array.
return $records;
});