连接 table created_at 和 updated_at 值未设置

Joining table created_at and updated_at values not being set

我有两个模型,产品和属性。在'products'和'attributes'之间有一个'product_attributes'连接table。该关系在两个模型中都使用 belongsToMany() 定义,table 的键是 product_id 和 attribute_id 的复合键。

我可以在连接 table 中成功检索和存储记录 - 因此,一切都按预期运行,除了 created_at 和 updated_at 中的 [=] 26=] 未设置。

以上是设计使然吗?我能做些什么来纠正这个问题吗?

您应该使用带有 timestamps 声明的 belongsToMany 函数,如下所示:

$this->belongsToMany(<entity>)->withTimestamps();