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