has('bbox') && !empty($request->bbox)) { $bbox = explode(',', $request->bbox); if (count($bbox) === 4) { $minLng = (float) $bbox[0]; $minLat = (float) $bbox[1]; $maxLng = (float) $bbox[2]; $maxLat = (float) $bbox[3]; $query->where('latitude', '>=', $minLat) ->where('latitude', '<=', $maxLat) ->where('longitude', '>=', $minLng) ->where('longitude', '<=', $maxLng); } } // Filter by categories if ($request->has('categories') && !empty($request->categories)) { $categories = explode(',', $request->categories); $query->whereIn('category', $categories); } $customers = $query->get(); // return formatted data $data = $customers->map(function ($m) { return [ 'id' => $m->id, 'name' => $m->name, 'category' => $m->category ?? 'other', 'latitude' => (float) $m->latitude, 'longitude' => (float) $m->longitude, 'city' => $m->city ?? '', 'address' => $m->address ?? '' ]; }); return response()->json($data); } }