F
Filament6mo ago
kool

Duplicate Queries in Repeater with Relationship

How can I prevent duplicate queries when adding a select form inside a repeater? P.S: Order model with a relationship items() as a HasMany,
No description
3 Replies
kool
koolOP6mo ago
Form Implementation
Repeater::make('order-items')
->label('')
->addActionLabel('Add Problematic Item')
->reorderable(false)
->columns(['md' => 4])
->schema([
Select::make('items')
->label('Order Item')
->options(function (Order $record) {
return $record->items()->pluck('sku', 'id');
})
->required(),
TextInput::make('quantity')
->required(),
Select::make('reason')
->options(OrderItemUnavailableReason::toOptionsArray())
->required(),
TextInput::make('note'),
]);
Repeater::make('order-items')
->label('')
->addActionLabel('Add Problematic Item')
->reorderable(false)
->columns(['md' => 4])
->schema([
Select::make('items')
->label('Order Item')
->options(function (Order $record) {
return $record->items()->pluck('sku', 'id');
})
->required(),
TextInput::make('quantity')
->required(),
Select::make('reason')
->options(OrderItemUnavailableReason::toOptionsArray())
->required(),
TextInput::make('note'),
]);
-------------------------- If I added relationship, it does not work, I don't know why
Repeater::make('items')
->relationship()
->label('')
->addActionLabel('Add Problematic Item')
->reorderable(false)
->columns(['md' => 4])
->schema([
Select::make('items')
->relationship('items', 'sku')
->label('Order Item')
->required(),
TextInput::make('quantity')
->required(),
Select::make('reason')
->options(OrderItemUnavailableReason::toOptionsArray())
->required(),
TextInput::make('note'),
])
]
Repeater::make('items')
->relationship()
->label('')
->addActionLabel('Add Problematic Item')
->reorderable(false)
->columns(['md' => 4])
->schema([
Select::make('items')
->relationship('items', 'sku')
->label('Order Item')
->required(),
TextInput::make('quantity')
->required(),
Select::make('reason')
->options(OrderItemUnavailableReason::toOptionsArray())
->required(),
TextInput::make('note'),
])
]
kool
koolOP6mo ago
No description
kool
koolOP6mo ago
No description
Want results from more Discord servers?
Add your server