联接表的created_at和updated_at值未设置

Bry*_*ynJ 3 laravel laravel-5 laravel-orm

我有两个模型,Product和Attribute。在“产品”和“属性”之间有一个“ product_attributes”联接表。在两个模型中都使用belongsToMany()定义了该关系,并且表的键是product_id和attribute_id的复合之一。

我可以成功检索记录并将其存储在联接表中-因此,一切都按预期运行,但未设置product_attributes中的created_at和updated_at。

以上是设计使然,我可以做些什么来纠正此问题?

Nom*_*man 5

您应该将belongsToMany函数与如下timestamps声明一起使用:

$this->belongsToMany(<entity>)->withTimestamps();
Run Code Online (Sandbox Code Playgroud)