序盤
マイグレーションの作成
(terminal)
php artisan make:migration create_contacts_table
上記のように作成する。
マイグレーションファイル内での、外部キーの設定の記述
$table->foreignId('category_id')->constrained('categories')->cascadeOnDelete();
下記はこれと同義である。
$table->foreignId('category_id')->constrained()->cascadeOnDelete();
$table->foreignId('category_id')->constrained('categories')->OnDelete('cascade');
コメント