Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel prevent updated_at from updating for specific query [duplicate]

Tags:

php

mysql

laravel

I am using the standard updated_at and created_at on a table.

My results are ordered by updated_at since they can be edited.

However, on a page I am updating a row counter (views). This means that the updated_at will be updated with the new date/time but I want to prevent this.

Is there any way to do this? Or am I going to have to use created_at to order my results?

I would rather not use my own manual created_at and updated_at

like image 495
Cjmarkham Avatar asked Jul 02 '14 10:07

Cjmarkham


Video Answer


1 Answers

For single model queries:

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

For multiple model queries use

DB::table('products')->...->update(...)

instead of

Product::...->update(...)
like image 137
Luca C. Avatar answered Oct 04 '22 04:10

Luca C.