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?
13 Replies
LeandroFerreira
LeandroFerreira3mo ago
because ->relationship('order_details') ?
matin rajabi
matin rajabiOP3mo ago
It doesn't matter. Whether it's there or not, it still tries to save a record in order_details, and I get an error. 🫠
LeandroFerreira
LeandroFerreira3mo ago
Do you have the order_details relationship?
matin rajabi
matin rajabiOP3mo ago
yes. public function order_details(): HasMany { return $this->hasMany(OrderDetail::class); } here it is
LeandroFerreira
LeandroFerreira3mo ago
remove ->saveRelationshipsUsing(null)
matin rajabi
matin rajabiOP3mo ago
i got same error
LeandroFerreira
LeandroFerreira3mo ago
protected function handleRecordCreation(array $data): Model
{
dd($data);
}
protected function handleRecordCreation(array $data): Model
{
dd($data);
}
Does it show order_details ? ahh.. remove ->dehydrated()
matin rajabi
matin rajabiOP3mo ago
no. it looks like this: array:11 [▼ // app/Filament/Resources/OrderResource/Pages/CreateOrder.php:19 "phone" => "09102174715" "user_id" => 75 "admin" => 1 "address_id" => "1" "fname" => "متین" "lname" => "رجبی" "send_id" => "1" "order_type" => "حضوری" "price" => 150000 "send_price" => "20000" "final_price" => 170000 ]
LeandroFerreira
LeandroFerreira3mo ago
if you remove dehydrated, it should work
matin rajabi
matin rajabiOP3mo ago
nah. $data is look like this: array:11 [▼ // app/Filament/Resources/OrderResource/Pages/CreateOrder.php:19 "phone" => "09102174715" "user_id" => 75 "admin" => 1 "address_id" => "1" "fname" => "متین" "lname" => "رجبی" "send_id" => "1" "order_type" => "اینستاگرام" "price" => 225000 "send_price" => "20000" "final_price" => 245000 ]
LeandroFerreira
LeandroFerreira3mo ago
yep, order_details relationship should be saved automatically. What is the error when you try to save the record now?
matin rajabi
matin rajabiOP3mo ago
it says: Field 'product_id' doesn't have a default value (Connection: mysql, SQL: insert into order_details (order_id, updated_at, created_at) values (43, 2025-07-31 11:55:03, 2025-07-31 11:55:03))
LeandroFerreira
LeandroFerreira3mo ago
check product_id in your relationship. I don't think the issue is Filament

Did you find this page helpful?