How to update timestamp column in Laravel

Categorized as Laravel

If you want to update a timestamp column in a specific model, you can use touch method, instead of using update. This functionality has been added

Since Laravel 9.25 it is now also possible to use the touch method on the query builder as well (was only possible on a model previously).

$user = User::find(1);

// Instead of 
$user->update(['subscribed_at' => now()]);

// You can use
$user->touch('subscribed_at');

But remember, touch is applicable only for updating timestamps.

Some additional information could be found here.

Leave a reply

Your email address will not be published.