首页 文章

更新Eloquent模型而不触及时间戳(Laravel 3)?

提问于
浏览
0

我需要更新Laravel 3中的Eloquent模型而不触及自动时间戳 . 代码非常简单:

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

但是,这也会更新时间戳 . 我已经看到了这个:Update without touching timestamps (Laravel)但它似乎不适用于L3,或者我做错了什么 . 在Thread模型中有:

public static $timestamps = true;

这会更新数据库中的 updated_at timestamp字段 . 我需要以某种方式更新线程模型而不触及时间戳 . 谁知道怎么样?文档http://three.laravel.com/docs/database/eloquent没有关于此问题的任何内容......

2 回答

  • -1

    不确定这是否适用于L3,但在L4中我认为你可以这样做:

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

    用解决方法回答了我自己的问题 . 做就是了:

    $thread->views = $thread->views + 1;
    DB::table('threads')->where('id', '=', $thread->id)->update(array('views' => $thread->views));
    

相关问题