public function update(UserFormRequest $request, $id)
 {
     $user = User::findOrFail($id);
     $user->load(['profile', 'profile.extendedProfile']);
     $user->username = $request->input('username');
     $user->status = $request->input('status');
     $user->email = $request->input('email');
     if ($request->input('remove_profile_picture') == 1) {
         $user->profile->removeProfilePicture();
     }
     if ($request->hasFile('profile.profile_picture') && $request->file('profile.profile_picture')->isValid()) {
         $user->profile->profile_picture = $user->profile->saveProfilePicture($request->file('profile.profile_picture'));
     }
     if ($request->has('password')) {
         $user->password = bcrypt($request->input('password'));
     }
     $user->profile->fill($request->input('profile'));
     $user->profile->extendedProfile->fill($request->input('profile.extendedProfile'));
     $user->push();
     $subscriptions = [];
     foreach ($request->input('subscriptions', []) as $subscriptionSlug) {
         $subscriptions[] = Subscription::findBySlug($subscriptionSlug)->id;
     }
     $user->subscriptions()->sync($subscriptions);
     return redirect($request->get('backUrl', route('admin.member.index')))->with('messages', [$user->getName() . ' has been updated.']);
 }
 public function update(UserFormRequest $request, $id)
 {
     $user = User::findOrFail($id);
     $currentUser = Auth::user();
     if ($currentUser->is('normal_administrator') || $currentUser->is('property_manager') && $currentUser->profile->province != $user->profile->province) {
         return redirect()->back()->withErrors(['You are not authorized to do this.']);
     }
     $user->load(['profile', 'profile.extendedProfile']);
     //$user->username = $request->input('username');
     $user->email = $request->input('email');
     $user->status = $request->input('status');
     $user->manage_property = $request->input('manage_property', false);
     if ($request->input('remove_profile_picture') == 1) {
         $user->profile->removeProfilePicture();
     }
     if ($request->hasFile('profile.profile_picture') && $request->file('profile.profile_picture')->isValid()) {
         $user->profile->profile_picture = $user->profile->saveProfilePicture($request->file('profile.profile_picture'));
     }
     if ($request->has('password')) {
         $user->password = bcrypt($request->input('password'));
     }
     $user->profile->fill($request->input('profile'));
     $user->push();
     return redirect($request->get('backUrl', route('admin.agent.index')))->with('messages', [$user->getName() . ' has been updated.']);
 }