/**
  * @param int $id
  * @param Request $request
  *
  * @return \Crip\Core\Data\Model|\Illuminate\Http\JsonResponse|null
  *
  * @throws ActionCanceledException
  */
 public function update($id, Request $request)
 {
     $instance = $this->userRepository->find($id);
     $event_instance = new UserUpdate($instance, $id, $request, $this->setUser());
     if ($this->events->fire($event_instance) === false) {
         throw new ActionCanceledException('user-update');
     }
     $event_results = $this->events->fire(new UserUpdateValidate($id, $request, $instance));
     $validation_result = (new EventCollector())->push($event_results)->asValidator();
     if ($validation_result !== null) {
         return $validation_result;
     }
     return $this->userRepository->update($request->all(), $id, $instance);
 }
 /**
  * Handle social provider callback action for authorisation
  *
  * @param string $provider
  */
 public function handle($provider)
 {
     $user = $this->socialite()->driver($provider)->user();
     //Check is this email present in DB
     $existing = $this->social->findByProvider($user->getId(), $provider);
     if (empty($existing)) {
         //There is no combination of this social id and provider, so create new one
         // As there no use of user if social is not created, do this in database transaction
         $existing = DB::transaction(function () use($user, $provider) {
             $socialUser = $this->social->create(['social_id' => $user->getId(), 'provider' => $provider, 'user_id' => $this->user->create(['email' => $user->getEmail(), 'name' => $user->getName()])->id]);
             return $socialUser;
         });
     }
     Auth::login($existing->user, true);
 }