I have the following tables:
sku
orders
- id
- order number
- ship date
orderDetail
I am trying to return a JSON response of all 'orders' & 'orderDetails that have a given SKU. My sku model contains a hasMany relationship to orderDetails and hasManyThrough relationship to orders .
public function OrderDetails()
{
return $this->hasMany(OrderDetail::class);
}
public function orders()
{
return $this->hasManyThrough(order::class, orderDetail::class, 'order_id', 'id');
}
My order model contains a hasMany relationship to orderDetail
public function orderDetails()
{
return $this->hasMany(orderDetail::class);
}
what is the best way to query the orderDetail model to return data from the orderDetail model and the related orders model that will format well for JSON response.
return response()->JSON( compact( 'skuOrderData'), 200);
Disclaimer: if you already guessed, Im pretty new to this field and any help would be so appreciated. Thank you.