[英]automatic updating of timestamps in tables with no model
Doesn't laravel
automatically update the timestamps
of tables which have no model
, like a 'pivot'
table? laravel
不会自动更新没有model
的表的timestamps
,比如'pivot'
表吗? I have tried doing it but it doesn't update timestamps
. 我尝试过这样做,但它没有更新timestamps
。
And if it doesn't update it, is there a way we can do it using laravel
? 如果它不更新它,有没有办法我们可以使用laravel
? Or the only way is to update them manually by updating the columns 'created_at'
or 'updated_at'
? 或者唯一的方法是通过更新列'created_at'
或'updated_at'
来手动更新它们?
Laravel only updates those fields when you're using a modal. Laravel仅在您使用模态时更新这些字段。 If you want to update them manually then you can do so. 如果您想手动更新它们,那么您可以这样做。
DB::table('table')->where('id', '=', '1')->update(array(
'created_at' => date('Y-m-d H:i:s'),
'updated_at' => date('Y-m-d H:i:s')
));
Try the withTimestamp() on the relationship involving the pivot. 在涉及数据透视的关系上尝试使用withTimestamp()。
//class User
public function items()
{
return $this->belongsToMany('Items')->withTimestamps();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.