コード例 #1
0
 private function selfClaimBox($boxId, $userId)
 {
     if ($userId != \Auth::user()->id) {
         throw new \BB\Exceptions\AuthenticationException();
     }
     $box = $this->storageBoxRepository->getById($boxId);
     //Make sure the box is available
     if (!$box->available) {
         throw new \BB\Exceptions\ValidationException();
     }
     //Does the user have a box
     $this->memberStorage->setMember(\Auth::user()->id);
     $volumeAvailable = $this->memberStorage->volumeAvailable();
     if ($volumeAvailable < $box->size) {
         throw new \BB\Exceptions\ValidationException("You have reached your storage limit");
     }
     //Have the paid for a box
     if ($this->memberStorage->getRemainingBoxesPaidFor() <= 0) {
         throw new \BB\Exceptions\ValidationException("You need to pay the deposit first");
     }
     $this->storageBoxRepository->update($boxId, ['user_id' => \Auth::user()->id]);
 }