2 回答
![?](http://img1.sycdn.imooc.com/533e4ce900010ae802000200-100-100.jpg)
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();
});
}
并将您的关系添加到您的相关模型。这将缓解从同一领域到您的迁移。
![?](http://img1.sycdn.imooc.com/533e4cf4000151f602000200-100-100.jpg)
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 关注
- 124 浏览
添加回答
举报