我有一個包含多個表的遷移: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();
我應該使用不同的表為我的遷移制作多個模型嗎
慕無忌1623718
2021-07-13 17:41:54