Pregunta

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

¿Fue útil?

Solución 2

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));

Otros consejos

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

$thread->timestamps = false;
$thread->save();
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top