lundi 24 octobre 2016

Laravel 5 Eloquent cannot use 'having' on relationship

I need to get the vehicles whose relation(belongsTo) 'dealer's distance < 200

Vehicle::join('dealers', 'vehicles.dealer_id', '=', 'dealers.id')
   ->select(DB::raw("dealers.id, ( cos( radians(latitude) ) * cos( radians( longitude ) ) ) AS distance"))
   ->havingRaw('distance < 200');

I am trying to use havingRaw on the alias 'distance' from the relation (belongsTo) dealer. But failed with an error:

Column not found: 1054 Unknown column 'distance' in 'having clause'

Who is gonna make my day :)



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire