Update Only the “updated_at” Column On Your Model

LaravelPosted on

In some cases, it can be useful, to “touch” only the updated_at column on our model. By default, the model gets updated only, when we change something, so using the update() method would not update the timestamp if we don’t pass anything. To solve it we can use the touch() method:

// Retrieve the model
$model = Model::find($id);

// Update the "updated_at" column only
$model->touch();

Need a web developer? Maybe we can help, get in touch!

Looking for web dev job?
You can check them on Jooble.

To see and write comments, you must allow the related (Disqus) cookies. For more information, please visit our privacy policy page.

Similar Posts

More content in Laravel category