public function postStore() { $this->sanarInputProfesor(); $profesor = new Profesor(); $profesor->nombres = Request::input('nombres'); $profesor->apellidos = Request::input('apellidos'); $profesor->sexo = Request::input('sexo'); $profesor->tipo_doc = Request::input('tipo_doc'); $profesor->num_doc = Request::input('num_doc'); $profesor->ciudad_doc = Request::input('ciudad_doc'); $profesor->fecha_nac = Request::input('fecha_nac'); $profesor->ciudad_nac = Request::input('ciudad_nac'); $profesor->titulo = Request::input('titulo'); $profesor->estado_civil = Request::input('estado_civil'); $profesor->barrio = Request::input('barrio'); $profesor->direccion = Request::input('direccion'); $profesor->telefono = Request::input('telefono'); $profesor->celular = Request::input('celular'); $profesor->facebook = Request::input('facebook'); $profesor->email = Request::input('email'); $profesor->tipo_profesor = Request::input('tipo_profesor'); $profesor->save(); $this->sanarInputUser(); $this->checkOrChangeUsername($profesor->user_id); $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->is_active = Request::input('is_active', true); $usuario->tipo = 'Profesor'; $usuario->save(); $profesor->user_id = $usuario->id; $role = Role::where('name', '=', 'Profesor')->get(); $usuario->attachRole($role[0]); $profesor->save(); $profesor->user = $usuario; if (Request::input('grupo')['id']) { $grupo_id = Request::input('grupo')['id']; $matricula = new Matricula(); $matricula->alumno_id = $profesor->id; $matricula->grupo_id = $grupo_id; $matricula->matriculado = true; $matricula->save(); $grupo = Grupo::find($matricula->grupo_id); $profesor->grupo = $grupo; } return $profesor; }
/** * Creates a new Profesor model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Profesor(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->ID]); } else { return $this->render('create', ['model' => $model]); } }