亲爱的,我们用刷子送给你!
这是从依赖表中级联删除相关数据的实现:
class CreateCategoriesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up(): void
{
Schema::create('categories', static function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('category_id')->nullable();
$table->string('name')->unique();
$table->timestamps();
$table->foreign('category_id', 'categories_ibfk_1')
->references('id')->on('categories')
->onUpdate('CASCADE')
->onDelete('CASCADE');
});
}
...
}
如何在具有多态关系的迁移中实现相似?
class CreateImagesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up(): void
{
Schema::create('images', static function (Blueprint $table) {
$table->id();
$table->morphs('imageable');
$table->string('path');
$table->timestamps();
});
}
...
}