Beispiel #1
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);
 }
Beispiel #2
0
 /**
  * Store new user.
  *
  * @param array      $data
  * @param Admin/User $actor
  *
  * @return array
  */
 public function store(array $data, $actor, $provider = false)
 {
     $subscription = Subscription::whereIsDefault(1)->firstOrFail();
     $role = Role::whereName('user')->firstOrFail();
     $adtypes = [];
     foreach ($subscription->adtypes as $adtype) {
         $adtypes[$adtype->id] = ['number' => $adtype->pivot->number];
     }
     if (!isset($data['phone']) || empty($data['phone'])) {
         $data['is_phone'] = false;
     }
     $user = new User();
     $user->fill($data);
     if ($provider) {
         $user->is_validate = $data['is_validate'];
     }
     $user->subscription_id = $subscription->id;
     $user->role_id = $role->id;
     $user->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);
     event(new UserWillBeCreated($user, $actor, $adtypes));
     $user->save();
     $user->adtypes()->sync($adtypes);
     event(new UserWasCreated($user, $actor));
     return ['user' => $user];
 }