int("customer_id"); $customer = Customer::require($customer_id); $markers = []; $nvp = []; $location_id = $request->int("location_id"); if($location_id) { $nvp["id"] = $location_id; } $name = $request->string("name"); if($name) { $nvp["name"] = new HasTextConstraint($name); } $locations = $customer->getLocations($nvp); Address::load(array_column($locations, "address_id")); foreach($locations as $location) { $address = $location->getAddress(); $customer = $location->getCustomer(); if($address->hasGeolocation()) { $markers[] = [ "id" => (int) $location->id, "customer" => [ "id" => (int) $customer->id, "name" => $customer->name, "url" => $customer->getUrl() ], "name" => $location->name, "addressLinesHtml" => $address->getLinesHtml(), "latLng" => [ "lat" => (float) $address->latitude, "lng" => (float) $address->longitude, ], "url" => $location->getUrl(), ]; } } echo json_encode([ "success" => true, "markers" => $markers ]); break; default: throw new RuntimeException(__("Invalid action.")); } } catch(Exception $e) { Json::fail($e->getMessage()); }