Example #1
0
 /**
  * Save the changes.
  *
  * @param Issue $issue
  *
  * @return bool
  */
 public function persist(Issue $issue)
 {
     $issue->user_id = $issue->exists ? $issue->user_id : Auth::id();
     $issue->title = $this->input('title', $issue->title);
     $issue->description = $this->input('description', $issue->description);
     $issue->occurred_at = $this->input('occurred_at', $issue->occurred_at);
     if ($issue->save()) {
         // Check if we have any files to upload and attach.
         if (count($this->files) > 0) {
             foreach ($this->file('files') as $file) {
                 if (!is_null($file)) {
                     $issue->uploadFile($file);
                 }
             }
         }
         // Sync the issues labels.
         $labels = $this->input('labels', []);
         if (is_array($labels)) {
             $issue->labels()->sync($labels);
         }
         // Sync the issues users.
         $users = $this->input('users', []);
         if (is_array($users)) {
             $issue->users()->sync($users);
         }
         return true;
     }
     return false;
 }
Example #2
0
 /**
  * Operations to run upon deleting an issue.
  *
  * @param Issue $issue
  */
 public function deleting(Issue $issue)
 {
     // Make sure the model isn't soft deleted.
     if (!$issue->deleted_at) {
         // Detach the issue labels.
         $issue->labels()->detach();
         // Retrieve the comments attached to the current issue.
         $comments = $issue->comments()->get();
         // Detach the comments issue comments.
         $issue->comments()->detach();
         // Delete all of the comments.
         foreach ($comments as $comment) {
             $comment->delete();
         }
         // Delete the issue attachments.
         $files = $issue->files()->get();
         foreach ($files as $file) {
             $file->delete();
         }
     }
 }
Example #3
0
 /**
  * Save the changes.
  *
  * @param Issue $issue
  *
  * @return bool
  */
 public function persist(Issue $issue)
 {
     $issue->labels()->sync($this->input('labels', []));
     return true;
 }