/** * 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(); } } }
/** * Save the changes. * * @param Issue $issue * @param Comment $comment * * @return bool */ public function persist(Issue $issue, Comment $comment) { $comment->content = $this->input('content', $comment->content); $resolution = $this->input('resolution', false); // Make sure we only allow one comment resolution if (!$issue->hasCommentResolution() || $comment->resolution) { $issue->comments()->updateExistingPivot($comment->id, compact('resolution')); } if ($comment->save()) { // Check if we have any files to upload and attach them to the comment. if (count($this->files) > 0) { foreach ($this->file('files') as $file) { if (!is_null($file)) { $comment->uploadFile($file); } } } return true; } return false; }
/** * Save the changes. * * @param Issue $issue * * @return bool */ public function persist(Issue $issue) { $attributes = ['content' => $this->input('content'), 'user_id' => Auth::id()]; $resolution = $this->has('resolution'); // Make sure we only allow one comment resolution if ($issue->hasCommentResolution()) { $resolution = false; } // Create the comment. $comment = $issue->comments()->create($attributes, compact('resolution')); // Check that the comment was created successfully. if ($comment instanceof Comment) { // Check if we have any files to upload and attach them to the comment. if (count($this->files) > 0) { foreach ($this->file('files') as $file) { if (!is_null($file)) { $comment->uploadFile($file); } } } return $comment; } return false; }