Вопрос

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

Это было полезно?

Решение 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));

Другие советы

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

$thread->timestamps = false;
$thread->save();
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top