Level 17
Documentation available here: https://laravel.com/docs/5.8/eloquent-relationships
You'd do something like:
// in App\Order.php
public function products() {
return $this->belongsToMany(Product::class)
->withPivot([
'count',
]);
}
// in your function
public function newOrder() {
$order = Order::create($attrs)
->products()
->attach($product_id, [
'count' => 1 // or whatever value this needs to be.
]);
}
The attach function also takes an array so you can send it multiple IDs.