public function save()
 {
     $result = DB::transaction(function () {
         $result = array("result" => '', 'response' => '');
         $result["result"] = 'nothing2do';
         //respuesta para el resultado por defecto si no debo realizar ningun cambio
         $equipo = Input::get("e");
         //arreglo de id de socios
         $torneo_id = Input::get("torneo_id");
         //id del torneo
         $torneo_club_id = Input::get("t");
         //torneo_club_id
         $torneo_club = TorneoClub::where('id', $torneo_club_id)->first();
         $tr = new Trayectoria();
         $jugadores_actuales = [];
         $plantel = [];
         $i = 0;
         // ==================
         $director_tecnico = TorneoTecnico::where('torneo_club_id', $torneo_club->id)->get();
         foreach ($director_tecnico as $tecnico) {
             $tecnico->forceDelete();
         }
         $dt = Input::get("dt");
         $socio_dt = Socio::where('id', $dt)->first();
         if ($socio_dt) {
             $director_tecnico = TorneoTecnico::firstOrNew(['tecnico_id' => $dt, 'torneo_club_id' => $torneo_club->id]);
             $director_tecnico->save();
         }
         // ==================
         //$trayectoria_club =  $tr::where('club_id',$torneo_club->club_id)->whereNull('baja')->select('socio_id')->get();
         $jugadores_club_categoria = TorneoPlantel::with('jugador.jugador')->select('torneos_planteles.*')->join('temporadas_planteles', 'torneos_planteles.jugador_id', '=', 'temporadas_planteles.id')->join('torneos_clubes', 'torneos_planteles.torneo_club_id', '=', 'torneos_clubes.id')->join('socios', 'socios.id', '=', 'temporadas_planteles.jugador_id')->where('torneos_planteles.torneo_club_id', $torneo_club_id)->get();
         $habia_jugadores = count($jugadores_club_categoria);
         if ($habia_jugadores) {
             foreach ($jugadores_club_categoria as $p) {
                 $jugadores_actuales[] = $p->jugador->jugador_id;
             }
             $i = array_intersect($jugadores_actuales, $equipo);
             //Interseccion de jugadores cargados y seleccionados
             $insertar = array_diff($equipo, $i);
             //SOCIOS a insertar en la tabla
             $remover = array_diff($jugadores_actuales, $i);
             //SOCIOS a remover de la tabla
         } else {
             $insertar = $equipo;
         }
         $torneo = Torneo::where("id", $torneo_id)->first();
         if (isset($remover)) {
             foreach ($remover as $p) {
                 //elimino los jugadores que fueron removidos de la interface.
                 /*
                 $result = $tr::where('socio_id', $p)->whereNull('baja')->first();        
                 $result->forceDelete();
                 */
                 $jugador_temporada = TemporadaPlantel::where('temporada_id', $torneo->temporada_id)->where('jugador_id', $p)->first();
                 $jugador_torneo = TorneoPlantel::where('jugador_id', $jugador_temporada->id)->where('torneo_club_id', $torneo_club->id)->first();
                 if ($jugador_torneo) {
                     $jugador_torneo->forceDelete();
                 }
                 if ($jugador_temporada) {
                     $jugador_temporada->forceDelete();
                 }
                 //$result =  DB::table('trayectorias')->where('socio_id', $p)->softDeletes();
             }
         }
         if (count($insertar)) {
             foreach ($insertar as $p) {
                 //creo el arreglo asociativo de los nuevos jugadores
                 $plantel[] = array('alta' => date("Y-m-d"), 'alta_tipo' => 1, 'socio_id' => $p, 'club_id' => $torneo_club->club_id);
                 $jugador_temporada = TemporadaPlantel::firstOrNew(['temporada_id' => $torneo->temporada_id, 'jugador_id' => $p]);
                 $jugador_temporada->save();
                 $jugador_torneo = TorneoPlantel::firstOrNew(['jugador_id' => $jugador_temporada->id, 'torneo_club_id' => $torneo_club->id]);
                 $jugador_torneo->save();
             }
         }
         $result_ldbf = ($jugador_temporada and $jugador_torneo);
         // $result_trayectoria = (count($plantel)) ? DB::table('trayectorias')->insert($plantel) : true;         //inserto los socios o si solo removi devuelvo verdadero
         if ($result_ldbf) {
             $result["result"] = "Ok";
             $result["response"] = $result_ldbf;
         } else {
             $result["result"] = "Error";
             if ($jugador_temporada) {
                 $error = '***Error al agregar a la temporada***';
             }
             if ($jugador_torneo) {
                 $error = '***Error al agregar al torneo***';
             }
             $result["response"] = $error;
         }
         $this->jugadores_compartidos($torneo_club, $torneo);
         return $result;
     });
     return response()->json($result);
 }