Example #1
0
 /**
  * @param Request $request
  *
  * @return mixed
  */
 public function update(Request $request, Scrubber $scrubber)
 {
     $user = Auth::user();
     $this->validate($request, User::validationRules($user));
     $user->update(['first_name' => $request->get('first_name'), 'last_name' => $request->get('last_name'), 'email' => $request->get('email'), 'phone' => $scrubber->integer($request->get('phone')), 'gender' => $request->get('gender')]);
     // update user timezone
     $user = Auth::user();
     $settings = $user->settings;
     $settings->setTimezone($request->input('timezone'));
     $user->update(['settings' => $settings]);
     event('user.profile.updated', $user);
     return redirect('/dashboard')->withFlashSuccess('Your changes were saved');
 }
Example #2
0
 /**
  * @return mixed
  */
 public function postSetup(Request $request, Scrubber $scrubber)
 {
     $request->merge(['name' => 'Home', 'phone' => $scrubber->integer($request->get('phone'))]);
     $userRules = array_only(User::validationRules(), ['gender', 'phone', 'first_name', 'last_name']);
     $this->validate($request, array_merge(Address::validationRules(), $userRules), Address::validationMessages());
     //update the info
     DB::transaction(function () use($request) {
         $user = Auth::user();
         $user->first_name = $request->get('first_name');
         $user->last_name = $request->get('last_name');
         $user->phone = $request->get('phone');
         $user->gender = $request->get('gender');
         $user->save();
         // set timezone
         $settings = $user->settings;
         $settings->setTimezone($request->input('timezone'));
         $user->update(['settings' => $settings]);
         // add user address
         $address = App::make(Address::class, [$request->except(['first_name', 'last_name', 'phone', 'gender', 'timezone', 'answer', 'other'])]);
         $user->addresses()->save($address);
         $user->update(['primary_address_id' => $address->id]);
         // record survey
         if ($request->has('answer') && count($request->get('answer')) > 0) {
             $surveys = [];
             foreach ($request->get('answer') as $questionId => $answers) {
                 foreach ($answers as $answerId => $true) {
                     $surveys[] = app(RegistrationSurvey::class, [['answer_id' => $answerId]]);
                 }
                 // update that question's "Other"
                 if ($request->has('other.' . $questionId) && strlen($request->get('other')[$questionId]) > 0) {
                     $otherAnswer = RegistrationSurveyAnswer::where('question_id', $questionId)->where('answer', 'Other')->first();
                     $surveys[] = app(RegistrationSurvey::class, [['answer_id' => $otherAnswer->id, 'other' => $request->get('other')[$questionId]]]);
                 }
             }
             $user->surveys()->saveMany($surveys);
         }
     });
     return redirect('/dashboard');
 }