$get inside loop null, outside loop it is not

I am trying to access the $get of a wizard multi step form, but I can't access it inside my loop. The strange thing outside of the loop it works. Event when I try to store the value of $get in a variable and I try to access it inside loop, no success.
foreach ($items as $item) {
dd($get('purchase_price'));
if ($item['cost_type'] === PurchasedCostsType::SetAmount->value) {
$sumInCents += round(floatval($item['cost']) * 100);
} elseif ($item['cost_type'] === PurchasedCostsType::Percentage->value) {
$sumInCents += floatval($get('purchase_price')) * round(floatval($item['percent']) / 100, precision: 4);
}
}
foreach ($items as $item) {
dd($get('purchase_price'));
if ($item['cost_type'] === PurchasedCostsType::SetAmount->value) {
$sumInCents += round(floatval($item['cost']) * 100);
} elseif ($item['cost_type'] === PurchasedCostsType::Percentage->value) {
$sumInCents += floatval($get('purchase_price')) * round(floatval($item['percent']) / 100, precision: 4);
}
}
2 Replies
Kenji
Kenji3mo ago
Hi Did you get items value? I think Because of dd($get('purchase_price)) So Delete this row
TheNastyPasty
TheNastyPasty3mo ago
Already solved I did not have the $get('purchase_price') in my scope
Want results from more Discord servers?
Add your server
More Posts