-
-
Save troyxmccall/dea1a692f9b57d5f52d3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// I have Groups. A group can have many discussions. A single discussion can have many posts. | |
// models/Group.php | |
public function delete() | |
{ | |
// Check for discussions belonging to the group first | |
if ($this->discussions) { | |
foreach ($this->discussions as $discussion) { | |
$discussion->delete(); | |
} | |
} | |
// Remove entry in group_user pivot table | |
$this->users()->delete(); | |
// Now delete the group | |
return parent::delete(); | |
} | |
// models/Discussion.php | |
function delete() | |
{ | |
// Check for posts to discussion first | |
if ($this->posts) { | |
foreach ($this->posts as $post) { | |
$post->delete(); | |
} | |
} | |
// Now delete the discussion | |
return parent::delete(); | |
} | |
// The Post model does pretty much the same as the Discussion model. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment