2 回答

TA貢獻1818條經驗 獲得超11個贊
如果你的表中沒有更復雜的依賴關系,我建議你使用多態關系。創建一個表:
public function up()
{
Schema::create('processes', function (BlueprintCustom $table) {
$table->morphs('process');
$this->timestamp('processing_started_at')->nullable();
$this->timestamp('processing_ended_at')->nullable();
});
}
并將您的關系添加到您的相關模型。這將緩解從同一領域到您的遷移。

TA貢獻1863條經驗 獲得超2個贊
您可以創建一個繼承自的自定義藍圖類
Illuminate\Database\Schema\Blueprint
是這樣的:
namespace App\Whatever;
use Illuminate\Database\Schema\Blueprint;
class BlueprintCustom extends Blueprint {
public function customfields()
{
$this->string('source')->nullable();
$this->timestamp('processing_started_at')->nullable();
$this->timestamp('processing_ended_at')->nullable();
}
}
那么,在遷移時,您可以執行以下操作:
use App\Whatever\BlueprintCustom;
public function up()
{
Schema::create('newtable', function (BlueprintCustom $table) {
$table->increments('id');
$table->string('blah');
$table->customfields(); //This adds your fields
$table->timestamps();
});
}
- 2 回答
- 0 關注
- 155 瀏覽
添加回答
舉報