I
I
Ivan2020-08-03 10:37:54
Laravel
Ivan, 2020-08-03 10:37:54

How to specify that the updated_at field does not change when a query is made through the model?

Good afternoon. There is a task to change the active field in the users table to false if updated_at is more than 3 months old. I settled on this code:

User::where('active', true)
            ->whereDate('updated_at', '<=', now()->subMonths(3))
            ->update(['active' => false]);

Works as it should, but the updated_at field is also updated. How can I make the updated_at field not updated when this code is executed? Through DB:: table is not suitable, it is necessary through the model.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Daria Motorina, 2020-08-03
@Djonson86

update without touching timestamps

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question