Level 80
@motinska94 Not really, as no event is raised when attaching or detaching many-to-many records.
1 like
I have a Post model with many-to-many Tag relationships, and while detaching a tag from a post, I want to check if that tag is connected to any other post and remove it if it's not. Is there a way to do it? Here's what I want to happen in pseudo-code :
// App/Models/Post.php
protected static function boot(){
static::detaching(function(Post $post, Tag $tag){
if(!$tag->has('posts')){
$tag->delete();
}
});
}
@motinska94 Not really, as no event is raised when attaching or detaching many-to-many records.
Please or to participate in this conversation.