我有一個(gè)包含多個(gè)表的遷移:Status、Status_project、Status_task。我可以僅使用使用遷移命令創(chuàng)建的狀態(tài)模型來調(diào)用它們嗎?php artisan make:model 狀態(tài) -m我在幾個(gè)地方讀到我必須為每張桌子制作一個(gè)模型,但沒有其他方法嗎?除了 DB::table('statuses')。由于我的關(guān)系,我不喜歡多個(gè)模型例子: 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();
我應(yīng)該使用不同的表為我的遷移制作多個(gè)模型嗎
慕無忌1623718
2021-07-13 17:41:54