Example #1
0
 /**
  * регистрация
  * @return \Response
  */
 public function register()
 {
     Validation::prepareInput(['phone']);
     // всегда обязательные поля
     $fields = ['name', 'phone', 'email'];
     // регистрация может быть основна на адресе,
     // который был определен по промокоду
     if (\Input::get('address_id')) {
         $fields[] = 'address_id';
     } elseif (\Input::get('address')) {
         $fields[] = 'address';
     } else {
         // или при регистрации указывается полный адрес
         $fields[] = 'city';
         $fields[] = 'street';
         $fields[] = 'house';
         $fields[] = 'room';
         $fields[] = 'float';
     }
     $validator = Validation::validator($fields);
     if ($validator->fails()) {
         return $this->responseError($validator, 'Некорректные данные');
     }
     try {
         $api = new Api();
         $message = $api->RegistrNew(\Input::only($fields));
         // инвайт
         $invite = new InviteComponent();
         $cookie = $invite->registerInviteExternal($validator->getData()['phone']);
         $response = $this->responseSuccess([], $message);
         if ($cookie) {
             $response->withCookie($cookie);
         }
         return $response;
     } catch (\Exception $e) {
         return $this->responseException($e, 'Не удалось обработать данные');
     }
 }