F
Filamentβ€’13mo 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
yeonjihβ€’13mo ago
up
LeandroFerreira
LeandroFerreiraβ€’13mo 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
yeonjihβ€’13mo 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β€’13mo 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
yeonjihβ€’13mo ago
Thanks. I will try this,
yeonjih
yeonjihβ€’13mo ago
I got an error,
LeandroFerreira
LeandroFerreiraβ€’13mo ago
copy my example
yeonjih
yeonjihβ€’13mo ago
Thank you very much. your code works πŸ™‚
Want results from more Discord servers?
Add your server