在数据透视表中附加数据时时间戳不更新 [英] Timestamps are not updating while attaching data in pivot table
本文介绍了在数据透视表中附加数据时时间戳不更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用以下附加语句在数据透视表中创建一行.
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();
- 对于 Laravel 4.2:使用数据透视表李>
- Laravel 5.0:使用数据透视表
- Laravel 5.1:检索中间表列
- Laravel 5.2:通过中间表列过滤关系
- Laravel 5.3:通过中间表列过滤关系
- Laravel 5.4:检索中间表列
- Laravel 5.5:检索中间表列
- Laravel 5.6:检索中间表列
- Laravel 5.7:检索中间表列
- Laravel 5.8:检索中间表列
这篇关于在数据透视表中附加数据时时间戳不更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文