here what I tried to get but it returns empty between 2 given coordinates
function searchListings(){ $query = Listings::query(); $sw_lat = request('sw_lat'); $ne_lat = request('ne_lat'); $sw_lng = request('sw_lng'); $ne_lng= request('ne_lng'); $query->whereBetween('latitude', [$sw_lat, $ne_lat])->whereBetween('longitude', [$sw_lng, $ne_lng]); return $query::paginate(5); }
Advertisement
Answer
Check datatype
Use a numeric database column type. Example of errors with a text/varchar column:
User::truncate(); User::factory()->count(1)->create(['name' => 1.5]); User::whereBetween('name', [1,2])->paginate()->first(); // One result User::truncate(); User::factory()->count(1)->create(['name' => -1.5]); User::whereBetween('name', [-2,-1])->paginate()->first() // No results (!)