Does RepeatableEntry support arrays or only models?

I am currently working on a project and trying to use RepeatableEntry to manage dynamic entries for product totals. I've structured my RepeatableEntry as follows:
return RepeatableEntry::make('productTotals')
->label(__('Product Totals'))
->columns(3)
->state(function ($record) {
// Demo array to test
return [
[
'product' => 'Product 1',
'quantity' => 1,
'price' => 100,
'total' => 100,
],
[
'product' => 'Product 2',
'quantity' => 2,
'price' => 200,
'total' => 400,
],
];
})
->schema([
TextEntry::make('product')
]);
return RepeatableEntry::make('productTotals')
->label(__('Product Totals'))
->columns(3)
->state(function ($record) {
// Demo array to test
return [
[
'product' => 'Product 1',
'quantity' => 1,
'price' => 100,
'total' => 100,
],
[
'product' => 'Product 2',
'quantity' => 2,
'price' => 200,
'total' => 400,
],
];
})
->schema([
TextEntry::make('product')
]);
However, it appears that the RepeatableEntry is not displaying or functioning as expected. Does RepeatableEntry only work with Eloquent models, or can it also handle arrays like the one I am trying to use? Has anyone encountered this issue, and what solutions or workarounds might you suggest?
2 Replies
Cosme fulanito
Cosme fulanitoOP7mo ago
I looked into the code and noticed it seems geared towards handling Eloquent models specifically. Here’s what I found:
foreach ($this->getState() ?? [] as $itemKey => $itemData) {
$container = $this
->getChildComponentContainer()
->getClone()
->statePath($itemKey)
->inlineLabel(false);

if ($itemData instanceof Model) {
$container->record($itemData);
}
}
foreach ($this->getState() ?? [] as $itemKey => $itemData) {
$container = $this
->getChildComponentContainer()
->getClone()
->statePath($itemKey)
->inlineLabel(false);

if ($itemData instanceof Model) {
$container->record($itemData);
}
}
From this, it looks like non-model data like arrays doesn't get the same handling as models do. Has anyone successfully used RepeatableEntry with arrays? How did you manage it? Cheers!
tungon
tungon7mo ago
I have exactly the same problem. Have you been able to solve it yet?
Want results from more Discord servers?
Add your server