예제 #1
0
파일: UserService.php 프로젝트: zedx/core
 /**
  * Update the specified resource in storage.
  *
  * @param UpdateUserRequest $request
  *
  * @return bool
  */
 public function update($request)
 {
     $inputs = $request->all();
     if ($this->user->is_validate && !Hash::check($inputs['current_password'], $this->user->password)) {
         return false;
     }
     if (!$this->user->is_validate && empty($inputs['password'])) {
         return false;
     }
     if (!isset($inputs['phone']) || empty($inputs['phone'])) {
         $inputs['is_phone'] = false;
     }
     if (empty($inputs['password'])) {
         array_forget($inputs, ['password', 'password_confirm']);
     }
     if ($request->hasFile('avatar')) {
         $this->makeAvatarFor($this->user, $request->file('avatar'));
     }
     $this->user->fill($inputs);
     $this->user->is_validate = 1;
     event(new UserWillBeUpdated($this->user, $this->user));
     $this->user->save();
     event(new UserWasUpdated($this->user, $this->user));
     return true;
 }
예제 #2
0
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  *
  * @return Response
  */
 public function update(User $user, UpdateUserRequest $request)
 {
     $admin = Auth::guard('admin')->user();
     $inputs = $request->all();
     $subscription_id = isset($inputs['subscription_id']) ? $inputs['subscription_id'] : null;
     $subscription = Subscription::findOrFail($subscription_id);
     $adtypes = isset($inputs['adtypes']) ? $inputs['adtypes'] : [];
     if (empty($inputs['password'])) {
         array_forget($inputs, ['password', 'password_confirm']);
     }
     if (!isset($inputs['phone']) || empty($inputs['phone'])) {
         $inputs['is_phone'] = false;
     }
     $user->fill($inputs);
     $user->subscription()->associate($subscription)->save();
     $user->adtypes()->sync($adtypes);
     $user->subscribed_at = isset($inputs['subscribed_at']) ? $inputs['subscribed_at'] : Carbon::now()->format('d/m/Y');
     $user->subscription_expired_at = $subscription->days >= 9999 ? null : Carbon::createFromFormat('d/m/Y', $user->subscribed_at)->addDays($subscription->days + 1);
     $user->is_validate = 1;
     event(new UserWillBeUpdated($user, $admin));
     $user->save();
     event(new UserWasUpdated($user, $admin));
     return redirect()->route('zxadmin.user.edit', $user->id);
 }