/**
  * @param Request $request
  * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
  *
  * @var $user User
  * @var $userData UserData
  * @var $userSetting UserSetting
  */
 public function data(Request $request)
 {
     $user = User::find(Auth::user()->id);
     $userData = UserData::findOne($user->id);
     $userSetting = UserSetting::findOne($user->id);
     if ($request->isMethod('post')) {
         $messages = ['require' => 'The :attribute and :other must match.', 'same' => 'The :attribute and :other must match.', 'size' => 'The :attribute must be exactly :size.', 'between' => 'The :attribute must be between :min - :max.', 'in' => 'The :attribute must be one of the following types: :values', 'max' => 'Поле :attribute не должно быть длиной больше чем :value'];
         $data = $request->all();
         $validator = Validator::make($data, ['first_name' => 'max:100', 'last_name' => 'max:100', 'status' => 'max:255', 'country' => 'max:255', 'city' => 'max:255', 'hobby' => 'max:255', 'activity' => 'max:255', 'location' => 'max:255', 'date_of_birth' => 'max:10|date|date_format:"d.m.Y"|before:"now"', 'date_of_birth_view_type' => 'between:0,' . count(User::getDateViewTypes()), 'social_network_vk' => 'max:255', 'social_network_fb' => 'max:255', 'social_network_tw' => 'max:255', 'social_network_in' => 'max:255', 'social_network_skype' => 'max:255', 'social_homepage' => 'max:255', 'gender' => 'in:0,1', 'relationship' => 'between:0,' . count($user->getRelationship())], $messages);
         if ($validator->fails()) {
             $this->throwValidationException($request, $validator);
         }
         $userData->first_name = $data['first_name'];
         $userData->last_name = $data['last_name'];
         $userData->status = $data['status'];
         $userData->country = $data['country'];
         $userData->city = $data['city'];
         $userData->hobby = $data['hobby'];
         $userData->activity = $data['activity'];
         $userData->location = $data['location'];
         $userData->date_of_birth = $data['date_of_birth'];
         $userData->social_network_vk = $data['social_network_vk'];
         $userData->social_network_fb = $data['social_network_fb'];
         $userData->social_network_tw = $data['social_network_tw'];
         $userData->social_network_in = $data['social_network_in'];
         $userData->social_network_skype = $data['social_network_skype'];
         $userData->social_homepage = $data['social_homepage'];
         $userData->gender = $data['gender'];
         $userData->relationship = $data['relationship'];
         $userData->save();
         $userSetting->date_of_birth_view_type = $data['date_of_birth_view_type'];
         $userSetting->save();
         $request->session()->flash('message', trans('user::settings.saved'));
     }
     return view('user::settings/data', ['user' => $user, 'userData' => $userData]);
 }
 /**
  * Регистрация пользователя
  * @param Request $request
  * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
  */
 public function postSave(Request $request)
 {
     $validator = Validator::make($request->all(), ['email' => 'required|email|max:255|unique:users', 'name' => 'max:255|min:1', 'surname' => 'max:255|min:1', 'gender' => 'in:0,1', 'login' => 'required|max:64|min:2|unique:users', 'anonymous_nick' => 'required|max:64|min:2|unique:users_data', 'password' => 'required|min:6|max:100']);
     if ($validator->fails()) {
         $this->throwValidationException($request, $validator);
     }
     $data = $request->all();
     //Создаем пользователя
     $user = User::create(['login' => $data['login'], 'email' => $data['email'], 'password' => bcrypt($data['password'])]);
     if ($user) {
         //Сразу Авторизовываем его
         Auth::login($user);
         //Удаляем неактивированный аккаунт
         $account = UsersActivation::where('email', $request->email)->first();
         $account->delete();
         //Сохраняем информацию о нём
         UserData::create(['user_id' => Auth::user()->id, 'anonymous_nick' => $data['anonymous_nick'], 'first_name' => $data['name'], 'last_name' => $data['surname'], 'gender' => $data['gender']]);
         //Создаем запись в таблице настроек и записываем первые значения
         UserSetting::create(['user_id' => Auth::user()->id, 'date_of_birth_view_type' => 0, 'lang' => 'ru']);
         return redirect($this->redirectPath());
     } else {
         return redirect($this->redirectPath())->with(['message' => trans('user::messages.reg.something_goes_wrong')]);
     }
 }