/** * Creates a new Alumno model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $hoy = date('Y-m-d H:i:s'); $perfil = new Perfil(); $perfil->fecha_alta = $hoy; $alumno = new Alumno(); $alumno->estado_id = EstadoAlumno::findOne(['descripcion' => EstadoAlumno::PREINSCRIPTO])->id; // Ver http://www.yiiframework.com/forum/index.php/topic/53935-subforms/page__gopid__248185#entry248185 if ($perfil->load(Yii::$app->request->post()) && Model::validateMultiple([$perfil, $alumno])) { $perfil->save(false); $alumno->perfil_id = $perfil->id; $alumno->save(false); return $this->redirect(['view', 'id' => $alumno->id]); } else { return $this->render('create', ['model' => $alumno, 'perfil' => $perfil]); } }
public function postStore() { $user = User::fromToken(); $alumno = []; try { $this->sanarInputAlumno(); $date = Carbon::createFromFormat('Y-m-d', Request::input('fecha_nac')); $alumno = new Alumno(); $alumno->no_matricula = Request::input('no_matricula'); $alumno->nombres = Request::input('nombres'); $alumno->apellidos = Request::input('apellidos'); $alumno->sexo = Request::input('sexo'); #$alumno->user_id = Request::input('user_id'); $alumno->fecha_nac = $date->format('Y-m-d'); $alumno->ciudad_nac = Request::input('ciudad_nac'); $alumno->tipo_doc = Request::input('tipo_doc'); $alumno->documento = Request::input('documento'); $alumno->ciudad_doc = Request::input('ciudad_doc'); $alumno->tipo_sangre = Request::input('tipo_sangre')['sangre']; $alumno->eps = Request::input('eps'); $alumno->telefono = Request::input('telefono'); $alumno->celular = Request::input('celular'); $alumno->barrio = Request::input('barrio'); $alumno->estrato = Request::input('estrato'); $alumno->ciudad_resid = Request::input('ciudad_resid'); $alumno->religion = Request::input('religion'); $alumno->email = Request::input('email'); $alumno->facebook = Request::input('facebook'); $alumno->pazysalvo = Request::input('pazysalvo'); $alumno->deuda = Request::input('deuda'); $alumno->save(); $this->sanarInputUser(); $this->checkOrChangeUsername($alumno->user_id); $yearactual = Year::actual(); $periodo_actual = Periodo::where('actual', true)->where('year_id', $yearactual->id)->first(); $usuario = new User(); $usuario->username = Request::input('username'); $usuario->password = Hash::make(Request::input('password', '123456')); $usuario->email = Request::input('email2'); $usuario->is_superuser = Request::input('is_superuser', false); $usuario->periodo_id = $periodo_actual->id; $usuario->is_active = Request::input('is_active', true); $usuario->tipo = 'Alumno'; $usuario->save(); $role = Role::where('name', 'Alumno')->get(); $usuario->attachRole($role[0]); $alumno->user_id = $usuario->id; $alumno->save(); $alumno->user = $usuario; if (Request::input('grupo')['id']) { $grupo_id = Request::input('grupo')['id']; $matricula = new Matricula(); $matricula->alumno_id = $alumno->id; $matricula->grupo_id = $grupo_id; $matricula->matriculado = true; $matricula->save(); $grupo = Grupo::find($matricula->grupo_id); $alumno->grupo = $grupo; } return $alumno; } catch (Exception $e) { return abort('400', $alumno); //return $e; } }