Indexes: Foreign Key Constraints

Schema::table('posts', function (Blueprint $table) {
    $table->unsignedInteger('user_id');

    $table->foreign('user_id')->references('id')->on('users');
});
$table->foreign('user_id')
      ->references('id')->on('users')
      ->onDelete('cascade');
$table->dropForeign('posts_user_id_foreign');
$table->dropForeign(['user_id']);
Schema::enableForeignKeyConstraints();

Schema::disableForeignKeyConstraints();

Foreign key constraints use the same naming convention as indexes.

Related concepts

Foreign Key Constraints

Indexes: Foreign Key Constraints — Structure map

Clickable & Draggable!

Indexes: Foreign Key Constraints — Related pages: