Code?
Aside, I would consider not putting the aggregated values in the orders tables as these can easily be derived from the related order_product table
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi guys! I have a table for Customers, Orders and OrderProducts. Now I want to put 'customer_id' into 'orders' table and also total items, 'quantity' and ' date'. This is how I save my customer data into customers table.
@xamshah you need to create the customer first and then the Orderand the oprde
public function create (Request $request){
$validatedData = $this->validate($request,[
'firstname' => ['required', 'string', 'max:255'],
'lastname' => ['required', 'string'],
'email' => ['required', 'string', 'email', 'max:255'],
'phone'=>['required'],
'country'=>['required'],
'city'=>['required'],
'zipcode'=>['required'],
'address'=>['required'],
]);
\DB::transaction(function () use ($validatedData) {
$customer= Customer::create($validatedData);
$order = $customer->orders()->create([
'items' => 0, // get from the Cart
'total' => 0, // get from the Cart
'date' => now(),
]);
});
if($order){
session()->forget('cart');
return view('frontend.checkout.orderconfirm')->with('success','Order Placed');
}
}
I don't know how you store items in the Cart, or how you move them from the Cart into the order_products table; perhaps you can share that schema.
Please or to participate in this conversation.