Why repeater data does not included in mutateFormDataBeforeCreate() function?

How do I access repeater data from the CreateInvoice Pages? It gave me this error:
Undefined array key "item_variations"
Undefined array key "item_variations"
I tried to dump the $data and the key for the repeater does not exist. My code:
<?php
class CreateInvoice extends CreateRecord
{
protected static string $resource = InvoiceResource::class;
protected function mutateFormDataBeforeCreate(array $data): array
{
\Midtrans\Config::$serverKey = config('midtrans.serverKey');
\Midtrans\Config::$isProduction = false;
\Midtrans\Config::$isSanitized = true;
\Midtrans\Config::$is3ds = true;
$repeater = $data['item_variations'];
$totalPrice = 0;
for ($i=0; $i < count($repeater); $i++) {
$totalPrice += $repeater[$i]['price'];
}
$partner = Partner::find($data['partner_id']);

$params = array(
'transaction_details' => array(
'order_id' => rand(),
'gross_amount' => $totalPrice,
),
'customer_details' => array(
'first_name' => $partner->name,
'phone' => $partner->phone_number,
),
);

$snapToken = \Midtrans\Snap::getSnapToken($params);
$data['midtrans_order_id'] = $snapToken;

return $data;
}
}
<?php
class CreateInvoice extends CreateRecord
{
protected static string $resource = InvoiceResource::class;
protected function mutateFormDataBeforeCreate(array $data): array
{
\Midtrans\Config::$serverKey = config('midtrans.serverKey');
\Midtrans\Config::$isProduction = false;
\Midtrans\Config::$isSanitized = true;
\Midtrans\Config::$is3ds = true;
$repeater = $data['item_variations'];
$totalPrice = 0;
for ($i=0; $i < count($repeater); $i++) {
$totalPrice += $repeater[$i]['price'];
}
$partner = Partner::find($data['partner_id']);

$params = array(
'transaction_details' => array(
'order_id' => rand(),
'gross_amount' => $totalPrice,
),
'customer_details' => array(
'first_name' => $partner->name,
'phone' => $partner->phone_number,
),
);

$snapToken = \Midtrans\Snap::getSnapToken($params);
$data['midtrans_order_id'] = $snapToken;

return $data;
}
}
Solution:
$this->data is non-validated. You didn’t provide that part of the code but I guess you are using a relationship that’s why it’s not included in data because it’s saved directly to your relationship
Jump to solution
2 Replies
shopeebot
shopeebotOP6mo ago
Turns out the key is hiding on "$this->data" instead of regular "$data" Can someone enlighten me how is this different?
Solution
Dennis Koch
Dennis Koch6mo ago
$this->data is non-validated. You didn’t provide that part of the code but I guess you are using a relationship that’s why it’s not included in data because it’s saved directly to your relationship
Want results from more Discord servers?
Add your server