public function atender_atencion(Request $request) { header("Access-Control-Allow-Origin: *"); header("Allow: GET, POST, OPTIONS"); $id = $request->input('id'); $estado_id = $request->input('estado_id'); $consulta = ""; $atencion = Atencion::find($id); $atencion->estado_id = $estado_id; if ($estado_id == 2) { $atencion->fecha_atendido = Carbon::now(); } if ($estado_id == 3) { $atencion->fecha_ausente = Carbon::now(); } $atencion->save(); //$telefono_avisar=DB::table('atencions')->select(DB::raw('telefono'))->where('colaborador_id','=',null)->where('id','>',40)->where('estado_id','=','1')->orderBy('posicion','desc')->take(3)->first()->telefono; $ids = DB::table('atencions')->select(DB::raw('id'))->where('colaborador_id', '=', null)->where('id', '>', $id)->where('estado_id', '=', '1')->where('lista_id', '=', $atencion->lista_id)->orderBy('posicion', 'asc')->take(3)->get(); if (count($ids) == 3) { $atencion_aviso = Atencion::find($ids[2]->id); if ($atencion_aviso->telefono == null) { $telefono = User::find($atencion_aviso->user_id)->telefono; if ($telefono == null) { $telefono = "no hay telefono"; } } else { $telefono = $atencion_aviso->telefono; } //aca se envia el sms al telefono $mensaje = "Quedan%203%20personas%20para%20su%20turno:" . $telefono; //$consulta=json_decode(file_get_contents("https://rest.nexmo.com/sms/json?api_key=1e6c4f1d&api_secret=d7484e91&from=NEXMO&to=51994085900&text=".$mensaje), true); } else { $telefono = ""; } //return $atencion; return ["telefono" => $telefono, "consulta" => $consulta, "usuario" => User::find($atencion->user_id)]; }