So hear me out. If I place an order, I would like to store the order and the actual order details. One table to store the orderID, productID, order_status and is_delivered whereas the other table contains of the delivery address, price and quantity.
I have setup the relations and everything, but one thing that I am trying to figure out is:
How do I retrieve the orderID from the order so I can insert it into the order_details table as my foreign key in one go? Is there any chance that this is possible?
Any help would be appreciated. Thanks!
I assume you have one to many relation between order
and order_details
$order = Order::create($orderData);
$orderDetails = [
[$orderDetailsArray_1],
[$orderDetailsArray_2],
];
$order->order_details->createMany($orderDetails);
This will save relational data on thy fly. See the DOC to learn more.