Laravel Eloquent using ->selectRaw()

Viewed 307

I'm trying to implement the code below. But, of course, my $apartment_list is empty, and I only have the calculated distance and services & sponsors empty. So I know that the code is wrong; how can I fix it?

$apartment_list = Apartment::with(['services', 'sponsors'])
    ->selectRaw('( 6371 * acos( cos( radians(?) ) *
                    cos( radians( latitude ) )
                        * cos( radians( longitude ) - radians(?)
                    ) + sin( radians(?) ) *
                        sin( radians( latitude ) ) )
                    ) AS distance', [$lat_from, $lon_from, $lat_from])
    ->orderByRaw('distance')
    ->havingRaw("distance < ?", [$km_radius])
    ->get();
0 Answers
Related