简体   繁体   English

更新雄辩的模型而无需更改时间戳(Laravel 3)?

[英]Update Eloquent model without touching timestamp (Laravel 3)?

I need to update an Eloquent model in Laravel 3 without touching the automatic timestamp. 我需要在Laravel 3中更新Eloquent模型,而无需触碰自动时间戳。 Code is super simple: 代码非常简单:

$thread->views = $thread->views + 1;
$thread-> save();

However that also updates the timestamp. 但是,这也会更新时间戳。 I've seen this: Update without touching timestamps (Laravel) but it does not seem to work in L3, or maybe I've done something wrong. 我已经看到了这一点: 更新时未触及时间戳(Laravel),但它似乎在L3中不起作用,或者我做错了什么。 In the Thread model there is: 在线程模型中有:

public static $timestamps = true;

Which updates the updated_at timestamp field in the database. 哪个更新数据库中的updated_at时间戳字段。 I need to update the thread model somehow without touching the timestamp. 我需要以某种方式更新线程模型而无需触碰时间戳。 Anyone know how? 有人知道吗? The documentation http://three.laravel.com/docs/database/eloquent does not have anything about this issue... 文档http://three.laravel.com/docs/database/eloquent没有关于此问题的任何信息...

Not sure if this works for L3, but in L4 I think you can do: 不知道这是否适用于L3,但在L4中,我认为您可以这样做:

$thread->timestamps = false;
$thread->save();

Answered my own question with a workaround. 解决方法回答了我自己的问题。 Just do: 做就是了:

$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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM