Skip to main content
Tutorial Free

New in Laravel 9.25: touch() on Query Builder

September 27, 2022
1 min read

In one of the recent Laravel versions, they released an improvement to use the touch() method on Query Builder, and not only on Eloquent Model.

But, maybe some of you don't know what the touch() method does.

Generally, it is used if you don't want to update any data on your model, just save the fact that it was updated:

$user = User::find($id);
$user->touch();

It will be the same as doing:

$user = User::find($id);
$user->updated_at = now();
$user->save();

You can also use touch() on any timestamp field, like $user->touch('activated_at');

Now, in Laravel 9.25, Steve Bauman suggested a PR to add the same functionality to the Query Builder, so you would be able to "mass-touch" many models, in one sentence:

User::where('email', 'like', '%@company.com')->touch();

It would do the same update in the database, just by your query, and not a specific single model.

Enjoyed This Tutorial?

Get access to all premium tutorials, video and text courses, and exclusive Laravel resources. Join our community of 10,000+ developers.

Recent Courses

Laravel Coding with AI Agents: Cursor, Claude Code, Codex

5 lessons
1 h 01 min

Filament 4 From Scratch

28 lessons
2 h 25 min

NativePHP: Build Mobile App with Laravel

11 lessons
2 h 2 min read

Comments & Discussion

No comments yet…

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.