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

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

问题描述

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

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

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

这将在数据透视表中插入一行,但是,它没有更新时间戳.时间戳记仍为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() 关系定义的方法.

If you want your pivot table to have automatically maintained created_at and updated_at timestamps, use the withTimestamps() method on the relationship definition.

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:检索中间表列
    • For Laravel 4.2: Working With Pivot Tables
    • Laravel 5.0: Working With Pivot Tables
    • Laravel 5.1: Retrieving Intermediate Table Columns
    • Laravel 5.2: Filtering Relationships Via Intermediate Table Columns
    • Laravel 5.3: Filtering Relationships Via Intermediate Table Columns
    • Laravel 5.4: Retrieving Intermediate Table Columns
    • Laravel 5.5: Retrieving Intermediate Table Columns
    • Laravel 5.6: Retrieving Intermediate Table Columns
    • Laravel 5.7: Retrieving Intermediate Table Columns
    • Laravel 5.8: Retrieving Intermediate Table Columns
    • 这篇关于在数据透视表中附加数据时,时间戳记未更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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