【发布时间】:2021-06-22 14:56:39
【问题描述】:
我有一个 Equipment 模型,它是多态多对多与其他一些模型。
这是我无法弄清楚的问题。当一个设备添加到另一个模型时,hours 将在设备上每次更改。所有其他字段、sn、make、model 都是静态的。我想进行设置,以便记录对小时字段的每次更改 - 这样我就可以查询历史记录。
我应该将小时数移至equipables 表吗?添加数据透视表?最好的设置方法是什么?
这里是此模型和Equipables poly 关系的迁移概述。
Schema::create('equipment', function (Blueprint $table) {
$table->id();
$table->string('sn')->index();
$table->string('make');
$table->string('model');
$table->string('stock');
$table->string('hours');
$table->timestamps();
});
Schema::create('equipables', function (Blueprint $table) {
$table->integer("equipment_id");
$table->integer("equipable_id");
$table->string("equipable_type");
$table->timestamps();
});
感谢您提供的任何帮助。
【问题讨论】:
标签: laravel eloquent polymorphism pivot-table