I am trying to save an order
with order_items
but I am not really finding anything in the docs to support this use case. A hasMany relationship.
Basically there is an orders
table with something like id | user_id
and an order_items
table with id | order_id | product_id
.
How can I save()
the order and use an array of items at the same time without having to loop over the items and save them individually?
Is this possible?
Pseudo code assuming $items
is an array:
$items = Session::get("cart.items");
$order = new Order;
$order->user_id = Auth::user()->id;
$order->order_items = $items;
$order->save();