public function postStore(Guard $auth, CursosHomologadosRequest $request) { $postulante = Postulante::where('user_id', $auth->id())->first(); $num_homologacion = Homologacion::where('postulante', $postulante->id)->get()->count(); //dd($num_homologacion); if ($num_homologacion == 0) { $homologacion = new Homologacion(); $homologacion->pga = $request->get('pga'); $homologacion->postulante = $postulante->id; $homologacion->fecha = date("Y-m-d"); $homologacion->save(); } $homologacion = Homologacion::where('postulante', $postulante->id)->first(); $curso_homologado = new AsignaturaHomologada(); $curso_homologado->homologacion = $homologacion->id; $curso_homologado->asignatura = $request->get('codigo_1'); $curso_homologado->codigo_asignatura_intercambio = $request->get('codigo_2'); $curso_homologado->nombre_asignatura_intercambio = $request->get('nombre_asignatura_2'); $curso_homologado->save(); return response()->json(['message' => 'La asignatura se ha adjuntado a la homologación actual.']); }