Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Romain's avatar
Level 30

onDelete('cascade') means...

hey

very quick and easy one but I'm confused with the docs. When I write:

$table->foreignId('submitted_by')->references('id')->on('users')->onDelete('cascade');

I hope that means: When the user with that ID is deleted, then delete this record. Am I right or is it the other way around?

0 likes
2 replies
automica's avatar
automica
Best Answer
Level 54

@romain

DELETE CASCADE: When we create a foreign key using this option, it deletes the referencing rows in the child table when the referenced row is deleted in the parent table which has a primary key.

so if we delete user, any rows in other tables referencing user will also get deleted.

which means you are correct in your meaning.

Romain's avatar
Level 30

thanks, I feel better now :D

1 like

Please or to participate in this conversation.