sajad torkamani
$table->foreignId('user_id')
  ->constrained()
  ->cascadeOnDelete();

This will do three things:

  • Create an unsigned bigint column named user_id.
  • Add a foreign key constraint so that user_id references the column id on a users table.
  • Add the ON DELETE CASCADE referential action so that deleting the user with the id of user_id will delete the current record too.

Sources

Tagged: Laravel

Leave a comment

Your email address will not be published. Required fields are marked *