Lina

How to delete post_tags and tag in a same instruction

Posted 1 year ago by Lina

Hi friends,

I have this code and I want to do on the best way:

    public function deleteTag(Request $request)
    {
        Tag::find($request->id)->post_tags()->delete();
        return Tag::destroy($request->id);
    }

Delete the post_tags and the tags

post_tags (tag_id, post_id) tags(id, tag_name)

Please sign in or create an account to participate in this conversation.

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up

Channels

Reply to

Use Markdown with GitHub-flavored code blocks.