#development #eloquent #laravel #php
When you are using the touches
feature in Laravel, you sometimes want to save a model without updating the timestamps of its owners (e.g. when you are
running a migration script).
To save a model without touching
pass false
to save
method:
1$someModel = new SomeModel();
2
3// do something with your model
4
5$someModel->save(['touch' => false]);
Of course setTouchedRelations
will work as well:
1$someModel = new SomeModel();
2
3// do what you need
4
5$someModel->setTouchedRelations([]);
6$someModel->save();
If this post was enjoyable or useful for you, please share it! If you have comments, questions, or feedback, you can email my personal email. To get new posts, subscribe use the RSS feed.