F
Filamentβ€’2y ago
yeonjih

Computation from separate repeater

How to get the total of the inputtext value from separate repeater?
Solution:
```php Repeater::make('repeater') ->schema([...]), Placeholder::make('total')...
Jump to solution
8 Replies
yeonjih
yeonjihOPβ€’2y ago
up
LeandroFerreira
LeandroFerreiraβ€’2y ago
Repeater::make('repeater')
->schema([
TextInput::make('qtd')
->numeric()
->default(0)
->lazy(),
TextInput::make('price')
->default(0)
->lazy(),
Placeholder::make('total')
->content(fn ($get) => $get('qtd') * $get('price'))
])
Repeater::make('repeater')
->schema([
TextInput::make('qtd')
->numeric()
->default(0)
->lazy(),
TextInput::make('price')
->default(0)
->lazy(),
Placeholder::make('total')
->content(fn ($get) => $get('qtd') * $get('price'))
])
yeonjih
yeonjihOPβ€’2y ago
Hello. My problem is I want to sum the Total Amount of all repeaters and put it into inputtext or placeholder. can you guide me regarding of my problem ?
Solution
LeandroFerreira
LeandroFerreiraβ€’2y ago
Repeater::make('repeater')
->schema([...]),

Placeholder::make('total')
->content(function ($get) {
$total = Arr::map($get('repeater'), function ($item) {
return $item['qtd'] * $item['price'];
});

return array_sum(array_values($total));
})
Repeater::make('repeater')
->schema([...]),

Placeholder::make('total')
->content(function ($get) {
$total = Arr::map($get('repeater'), function ($item) {
return $item['qtd'] * $item['price'];
});

return array_sum(array_values($total));
})
Could be better I think
yeonjih
yeonjihOPβ€’2y ago
Thanks. I will try this,
yeonjih
yeonjihOPβ€’2y ago
I got an error,
LeandroFerreira
LeandroFerreiraβ€’2y ago
copy my example
yeonjih
yeonjihOPβ€’2y ago
Thank you very much. your code works πŸ™‚

Did you find this page helpful?