I've painted myself into a corner on this one. I have the following structure:
clients | locations | departments
orders
items
variants
order_item
I have a morphToMany relationship between variants and client, location, dept. A variant describes an item specific to a client, location or department with a specific price and other details. Variants belong to many orders via order_item (should really be order_variant but I expanded that and haven't changed it).
I want to create a report for any client/location/dept that shows orders down the left side, item-variants across the top and in each cell, the count of variants from that order.
I can't seem to figure out the best way without writing something that runs a gazillion queries. If I pull up all orders and iterate through variants I can't get a consistent itemization of the items across the top.
Order.php
public function variants() {
return $this -> belongsToMany('App\Variant', 'order_item', 'order_id', 'variant_id')
-> withPivot('id','variant_id','quantity','quantity_received','quantity_delivered','notes', 'createdby_user_id', 'weight', 'cost_billed', 'tax_billed', 'calc_by_weight', 'track_units');
}
Variant.php
public function orders() {
return $this -> belongsToMany('App\Order', 'order_item', 'variant_id', 'order_id')
-> withPivot('id','variant_id','quantity','quantity_received','quantity_delivered','notes', 'createdby_user_id', 'weight', 'cost_billed', 'tax_billed', 'calc_by_weight', 'track_units');
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire