I use Laravel 5.3 and try to return a cheb with this product and only the last order and with the latest price history , Both connections return nothing, but if I delete $q->latest()->first(); and replace it with simple orderBy() , I will get all the results. My request:
$data = $heist->with(['product'=> function($query) { $query->with(['orders' => function($q) { return $q->latest()->first(); }]); $query->with(['price_history' => function($q) { return $q->latest()->first(); }]); }])->orderBy('completed_at', 'DESC')->orderBy('active', 'DESC')->get();
source share