Exemplo n.º 1
0
 public function crearEstacion()
 {
     $nombre = $_REQUEST['nombre'];
     $codigo = $_REQUEST['codigo'];
     $longitud = $_REQUEST['longitud'];
     $latitud = $_REQUEST['latitud'];
     $estaciones = \App\Estacion::where('nombre', '=', $nombre)->orwhere('codigo', '=', $codigo)->get();
     if ($estaciones->first() == null) {
         $nueva_estacion = \App\Estacion::firstOrCreate(['nombre' => $nombre, 'codigo' => $codigo, 'longitud' => $longitud, 'latitud' => $latitud]);
         header('Content-Type: application/json');
         echo json_encode(['status' => true, 'mensaje' => 'Ok al guardar Estacion -> ' . $nueva_estacion->id]);
     } else {
         header('Content-Type: application/json');
         echo json_encode(['status' => false, 'mensaje' => 'ERROR: al guardar Estacion']);
     }
 }