where('nom', 'LIKE', "{$query}%") ->orderBy('nom', 'ASC')->take(30)->get(); } public static function getCitiesByCP($query) { return City::select('id', DB::raw("concat(nom,' (',code_postal,')') as text")) ->where('code_postal', 'LIKE', "%{$query}%") ->orderBy('nom', 'ASC')->take(30)->get(); } public static function getCPByCity($id) { $ville = self::get($id); return explode('-', $ville->code_postal); } public static function getNomByCity($id) { $ville = self::get($id); return $ville->nom; } public static function get($id) { return City::find($id); } public static function getCoords($adresse) { $geocode = app('geocoder')->geocode($adresse)->get(); if (! count($geocode)) { return false; } $res = $geocode[0]->getCoordinates()->toArray(); $latitude = $res[0]; $longitude = $res[1]; return ['latitude' => $latitude, 'longitude' => $longitude]; } public static function getCoordsByCity($id) { $ville = City::find($id); return ['latitude' => $ville->latitude, 'longitude' => $ville->longitude]; } }