Repeater sum Items and quantities
I have a problem, I have a repeater and I want to calculate the items and quantities, create a placeholder inside the repeater with the subtotal of the item, and a placeholder outside the repeater to calculate all the added items * quantities, until then it works perfectly, the problem I have is if I add more quantity, it doesn't update the total that is outside the repeater, any ideas?
Repeater::make('invoiceItems')...
TextInput::make('article_quantity')...
TextInput::make('article_price')...
Placeholder::make('subtotal')
->content(function ($get) {
$ar_price = intval($get('article_price'));
$ar_qty = intval($get('article_quantity'));
$sub = $ar_price * $ar_qty;
return '$' . number_format($sub, 2);
}),
Outside the repeater ......
Placeholder::make('Total')
->content(function ($get) {
return collect($get('invoiceItems'))
->pluck('subtotal')
->sum();
}),
Repeater::make('invoiceItems')...
TextInput::make('article_quantity')...
TextInput::make('article_price')...
Placeholder::make('subtotal')
->content(function ($get) {
$ar_price = intval($get('article_price'));
$ar_qty = intval($get('article_quantity'));
$sub = $ar_price * $ar_qty;
return '$' . number_format($sub, 2);
}),
Outside the repeater ......
Placeholder::make('Total')
->content(function ($get) {
return collect($get('invoiceItems'))
->pluck('subtotal')
->sum();
}),

