I have 3 tables: products, orders and pivot table (order_product).
And these models:
class Product extends Model
{
public function orders()
{
return $this->belongsToMany(Order::class)
->withPivot([
'quantity',
]);
}
}
class Order extends Model
{
public function products()
{
return $this->belongsToMany(Product::class)
->withPivot([
'quantity',
]);
}
}
I'd like to do a query where for each product have ordered quantity.
Thanks