在数据透视表中附加数据时时间戳不更新 [英] Timestamps are not updating while attaching data in pivot table

查看:14
本文介绍了在数据透视表中附加数据时时间戳不更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下附加语句在数据透视表中创建一行.

I'm creating a row in pivot table using the following attach statement.

$music = Music::find(1);
$music->users()->attach(1);

这会在数据透视表中插入一行,但它不会更新时间戳.时间戳仍然是 0000-00-00 00:00:00

This inserting a row in pivot table but, It is not updating the timestamp. The timestamp remains 0000-00-00 00:00:00

有什么方法可以更新数据透视表中的时间戳.?

Is there any way to update the timestamps in pivot table. ?

提前致谢,

推荐答案

如果您希望您的数据透视表自动维护created_at 和 updated_at 时间戳,使用 withTimestamps()关系定义的方法.

return $this->belongsToMany('Role')->withTimestamps();

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆