Пример #1
0
 /**
  * Delete a model
  * @param  PermissionModel    $model     The model we want to delete
  * @param  Player             $me        The user who wants to delete the model
  * @param  Closure|null       $onSuccess Something to do when the model is deleted
  * @throws ForbiddenException
  * @return mixed              The response to show to the user
  */
 protected function delete(PermissionModel $model, Player $me, $onSuccess = null)
 {
     if ($model->isDeleted()) {
         // We will have to hard delete the model
         $hard = true;
         $message = 'hardDelete';
         $action = 'Erase forever';
     } else {
         $hard = false;
         $message = 'softDelete';
         $action = 'Delete';
     }
     if (!$this->canDelete($me, $model, $hard)) {
         throw new ForbiddenException($this->getMessage($model, $message, 'forbidden'));
     }
     $successMessage = $this->getMessage($model, $message, 'success');
     $redirection = $this->redirectToList($model);
     return $this->showConfirmationForm(function () use($model, $hard, $redirection, $onSuccess) {
         if ($hard) {
             $model->wipe();
         } else {
             $model->delete();
         }
         if ($onSuccess) {
             $response = $onSuccess();
             if ($response instanceof Response) {
                 return $response;
             }
         }
         return $redirection;
     }, $this->getMessage($model, $message, 'confirm'), $successMessage, $action);
 }