Exemple #1
0
 /**
  * Creates a new Firm model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Firm();
     $address = new Address();
     if ($model->load(Yii::$app->request->post()) && $address->load(Yii::$app->request->post()) && $model->save()) {
         Yii::$app->getSession()->addFlash('success', "Запись \"{$model->name}\" успешно добавлена.");
         return $this->redirect(Url::previous() != Yii::$app->homeUrl ? Url::previous() : ['view', 'id' => $model->id]);
     } else {
         if (Yii::$app->request->referrer != Yii::$app->request->absoluteUrl) {
             Url::remember(Yii::$app->request->referrer ? Yii::$app->request->referrer : null);
         }
         if (!Yii::$app->request->isPost) {
             $model->load(Yii::$app->request->get());
         }
         return $this->render('create', ['model' => $model, 'address' => $address]);
     }
 }
Exemple #2
0
 /**
  * Create a new user instance after a valid registration.
  *
  * @param  array  $data
  * @return User
  */
 public function create(array $data)
 {
     $user = null;
     DB::transaction(function () use($data, &$user) {
         $firm = new Firm();
         $firm->full_organisation_name = $data['full_organisation_name'];
         $firm->organisation_name = $data['organisation_name'];
         $firm->okpo = $data['okpo'];
         $firm->ogrn = $data['ogrn'];
         $firm->inn = $data['inn'];
         $firm->kpp = $data['kpp'];
         $firm->rs = $data['rs'];
         $firm->bik = $data['bik'];
         $firm->bank = $data['bank'];
         $firm->ks = $data['ks'];
         $firm->face_position = $data['face_position'];
         $firm->face_fio = $data['face_fio'];
         $firm->base_document = $data['base_document'];
         $firm->place_address = $data['place_address'];
         $firm->post_address = $data['post_address'];
         $firm->contact_face_fio = $data['contact_face_fio'];
         $firm->phone = $data['phone'];
         $firm->save();
         //            $user = User::create([
         //                'name' => $data['name'],
         //                'email' => $data['email'],
         //                'password' => bcrypt($data['password']),
         //                'firm_id' => $firm->id,
         //                'role_id' => Role::CLIENT
         //            ]);
         $user = new User();
         $user->name = $data['name'];
         $user->email = $data['email'];
         $user->password = bcrypt($data['password']);
         $user->firm_id = $firm->id;
         $user->role_id = Role::CLIENT;
         $user->save();
     });
     return $user;
 }