Skip to content

[9.x] Add ability to Model::query()->touch() to mass update timestamps#43665

Merged
taylorotwell merged 2 commits into
laravel:9.xfrom
stevebauman:query-touch
Aug 15, 2022
Merged

[9.x] Add ability to Model::query()->touch() to mass update timestamps#43665
taylorotwell merged 2 commits into
laravel:9.xfrom
stevebauman:query-touch

Conversation

@stevebauman

Copy link
Copy Markdown
Contributor

This PR adds the touch($column = null) method to the Eloquent query builder.

This is a convenience method, allowing you to mass update a model's timestamp in the database table with or without query constraints:

Mass touching the updated at column:

$touched = User::query()->touch();

Mass touching the updated at column with constraints:

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

Mass touching a specific column:

$published = Post::query()->touch('published_at');

It behaves identically to $model->touch(), and accepts the same method argument.

Let me know your thoughts! Thanks for your time 🙏

Comment thread src/Illuminate/Database/Eloquent/Builder.php
Comment thread src/Illuminate/Database/Eloquent/Builder.php
@taylorotwell taylorotwell merged commit 07aae35 into laravel:9.x Aug 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants