issue with repeater and relationship
hey, i have a simple form with simple logic to submit
protected function handleRecordCreation(array $data): Model {
$user = \App\Models\User::firstOrCreate(
['phone' => $data['phone']],
['password' => bcrypt(Str::random(8))]
);
$data['user_id'] = $user->id;
// قیمت نهایی محصولات
$totalProductPrice = 0;
foreach ($data['order_details'] as $item) {
$product = \App\Models\Product::find($item['product_id']);
$price = $product->price_for_quantity($item['quantity']);
$totalProductPrice += ($price * $item['quantity']);
}
// محاسبه هزینه ارسال
if (isset($data['send_id'])) {
$send = \App\Models\Send::find($data['send_id']);
$sendPrice = $send?->price ?? 0;
} else {
$sendPrice = $data['custom_send_price'] ?? 0;
}
// مجموع نهایی قیمت
$data['price'] = $totalProductPrice;
$data['send_price'] = $sendPrice;
$data['final_price'] = $totalProductPrice + $sendPrice;
$record = static::getModel()::create($data);
return $record;
}
but it tries to save related record into order_details. i don't know why is the reason?
protected function handleRecordCreation(array $data): Model {
$user = \App\Models\User::firstOrCreate(
['phone' => $data['phone']],
['password' => bcrypt(Str::random(8))]
);
$data['user_id'] = $user->id;
// قیمت نهایی محصولات
$totalProductPrice = 0;
foreach ($data['order_details'] as $item) {
$product = \App\Models\Product::find($item['product_id']);
$price = $product->price_for_quantity($item['quantity']);
$totalProductPrice += ($price * $item['quantity']);
}
// محاسبه هزینه ارسال
if (isset($data['send_id'])) {
$send = \App\Models\Send::find($data['send_id']);
$sendPrice = $send?->price ?? 0;
} else {
$sendPrice = $data['custom_send_price'] ?? 0;
}
// مجموع نهایی قیمت
$data['price'] = $totalProductPrice;
$data['send_price'] = $sendPrice;
$data['final_price'] = $totalProductPrice + $sendPrice;
$record = static::getModel()::create($data);
return $record;
}
but it tries to save related record into order_details. i don't know why is the reason?
message.txt6.75KB