0

I need to update an Eloquent model in Laravel 3 without touching the automatic timestamp. 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. In the Thread model there is:

public static $timestamps = true;

Which updates the updated_at timestamp field in the database. 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...

Community
  • 1
  • 1
wnajar
  • 747
  • 1
  • 7
  • 27

2 Answers2

0

Not sure if this works for L3, but in L4 I think you can do:

$thread->timestamps = false;
$thread->save();
Jake Wilson
  • 88,616
  • 93
  • 252
  • 370
  • This hasn't worked for me in L3... if you can get it to work somehow would love to see though. – wnajar Apr 09 '14 at 02:04
-1

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));
wnajar
  • 747
  • 1
  • 7
  • 27