[英]Update Eloquent model without touching timestamp (Laravel 3)?
我需要在Laravel 3中更新Eloquent模型,而无需触碰自动时间戳。 代码非常简单:
$thread->views = $thread->views + 1;
$thread-> save();
但是,这也会更新时间戳。 我已经看到了这一点: 更新时未触及时间戳(Laravel),但它似乎在L3中不起作用,或者我做错了什么。 在线程模型中有:
public static $timestamps = true;
哪个更新数据库中的updated_at
时间戳字段。 我需要以某种方式更新线程模型而无需触碰时间戳。 有人知道吗? 文档http://three.laravel.com/docs/database/eloquent没有关于此问题的任何信息...
不知道这是否适用于L3,但在L4中,我认为您可以这样做:
$thread->timestamps = false;
$thread->save();
解决方法回答了我自己的问题。 做就是了:
$thread->views = $thread->views + 1;
DB::table('threads')->where('id', '=', $thread->id)->update(array('views' => $thread->views));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.