What does onDelete(‘cascade’) mean?

Short answer is: in your case, if you deleted a user, all posts related to him will be deleted too.

onDelete('cascade'); simply adds ON DELETE CASCADE rule to your database which specifies that the child data gets deleted when the parent data is deleted.

Note: take care of the typo (double semicolon)

$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)