Jul 2, 2017
0
Level 4
whereHas relationship getting the latest row, but want to do a where on this result
//model
public function latest_flight_stock()
{
return $this->hasOne('App\FlightStock')->latest();
}
//controller
$flights = Flight::with('latest_flight_stock')
->has('flight_stocks')
->orderBy('departure_datetime');
->whereHas('latest_flight_stock', function($query) use($request) {
$query->where('load', '>', 30);
})
->get();
but now its fetching the load higher then 30 from Flight stock but what i like to accomplish is fetching the lateststocks with a load higher then 30.
Please or to participate in this conversation.