I got an Order object which has many-to-many relation with products:
public function products() {
return $this->belongsToMany('App\Product', 'order_products')
->withPivot('count', 'price');
}
I accept in request an array with products, then I should attach it to the order. But if I got an array, not collection, then how should I do this right way? I can do it via loop in $request->products, but it seems to be wrong for me.
To be exact, I have an array:
$products = [
['id' => 4, 'count' => 5],
['id'=>5, 'count' => 3]
];
How to do an $order->products->attach() without any loop?