samedi 23 juin 2018

Eloquent doesn't recognize my alias

I've a query to search users with certain distance :

$q->addSelect(DB::raw(
    '( 6371 * acos(cos(radians(' . Auth::user()->latitude . '))' .
        '* cos( radians( users.latitude ) )' .
        '* cos( radians( users.longitude )' .
        '- radians(' . Auth::user()->longitude . ') )' .
        '+ sin( radians(' . Auth::user()->latitude . ') )' .
        '* sin( radians( users.latitude ) ) ) ) as distance'
));
$q->having('distance', '<', $search->distance);

I get this error : Column not found: 1054 Unknown column 'distance' in 'having clause'.

When I run the query in PhpMyAdmin with the return of $q->toSql();, my query works?!



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire