我有一个包含多个表的迁移:Status、Status_project、Status_task。我可以仅使用使用迁移命令创建的状态模型来调用它们吗?
php artisan make:model 状态 -m
我在几个地方读到我必须为每张桌子制作一个模型,但没有其他方法吗?除了 DB::table('statuses')。由于我的关系,我不喜欢多个模型
例子:
Schema::create('statuses', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('name')->unique();
$table->string('display_name')->nullable();
$table->string('description')->nullable();
$table->timestamps();
});
Schema::create('status_task', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('user_id')->nullable();
$table->unsignedBigInteger('task_id');
$table->unsignedBigInteger('status_id');
$table->foreign('user_id')->references('id')->on('users')
->onUpdate('cascade')->onDelete('cascade');
$table->foreign('task_id')->references('id')->on('ongoing_tasks')
->onUpdate('cascade')->onDelete('cascade');
$table->foreign('status_id')->references('id')->on('statuses')
->onUpdate('cascade')->onDelete('cascade');
});
Schema::create('status_project', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('user_id')->nullable();
$table->string('project_id');
$table->unsignedBigInteger('status_id');
$table->foreign('user_id')->references('id')->on('users')
->onUpdate('cascade')->onDelete('cascade');
$table->foreign('project_id')->references('id')->on('ongoing_projects')
->onUpdate('cascade')->onDelete('cascade');
$table->foreign('status_id')->references('id')->on('statuses')
->onUpdate('cascade')->onDelete('cascade');
});
DB::commit();
摇曳的蔷薇