public function jsonUbicacion() { if (Input::get('lat') && Input::get('lon')) { $lat = Input::get('lat'); $lon = Input::get('lon'); $ciudad = Ciudad::with('pais')->orderBy(DB::raw("SQRT(POW(69.1 * (lat - {$lat}), 2) + POW(69.1 * ({$lon} - lon) * COS(lat / 57.3), 2))", 'ASC'))->take(1)->get(); return Response::json($ciudad->toArray()); } }
/** * Display a listing of the resource. * * @return Response */ public function index($id = null) { if ($id == null) { $data['ciudades'] = Ciudad::with('Departamento')->orderBy('id', 'asc')->get(); $data['departamentos'] = Departamento::orderBy('id', 'asc')->get(); return $data; } else { return $this->show($id); } }