onDelete('cascade') Vs. Using Model Events to Delete records

Posted 1 month ago by thebigk

I've been using model events to delete related records. For example, if a post model is deleted, I'd use deleting model event to delete all the comments on the post. It works fine.

I now discovered onDelete('cascade') ; which I can define in my migrations.

I'm wondering if having database handle record deletion is better approach over using model events?

What's your take?

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


Reply to

Use Markdown with GitHub-flavored code blocks.