Accessing repeater value from outside

Need help, how do I get the value of those inside the repeater and make the price update every time I made changes inside the repeater?

This is my sample code:

Repeater::make('products')
->schema([
TextInput::make('quantity')
->live()
->default(100)
->afterStateUpdated(function (Set $set, $state) {
$set('quantity', $state);
})
TextInput::make('price')
->live()
->default(100)
->afterStateUpdated(function (Set $set, $state) {
$set('price', $state);
})

]),

TextInput::make('amount')
->default(function (Get $get) {
$quantity = (float) $get('../quantity');
$price = (float) $get('../price');
return $quantity * $price;
}),

It is always null.
Solution
Repeater::make('products')
  ->live()
    ->schema([
    TextInput::make('quantity')
            ->live()
                ->default(100)
                ->afterStateUpdated(function (Set $set, $state) {
                       $set('quantity', $state);
                })
    TextInput::make('price')
            ->live()
                ->default(100)
                ->afterStateUpdated(function (Set $set, $state) {
                       $set('price', $state);
                })

    ])
  ->afterStateUpdated(function (Get $get, Set $set) {
        $amount = 0;
        foreach($get('products', []) as $product) {
          $amount += ((int) $product['quanity'] * (float) $product['price']);
        }
        
        $set('amount', $amount);
   }),
Was this page helpful?