0

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

Alex
  • 17
  • 5
  • 1
    Be sure to search the site before posting a question, as it may answer your question https://stackoverflow.com/questions/28267550/how-to-group-and-sum-a-pivot-table-column-in-eloquent-relationship – mohammed albadry Jun 23 '23 at 10:36

0 Answers0