Open Braunson opened 3 years ago
You can also set $timestamps property in Model to false: https://laravel.com/docs/8.x/eloquent#timestamps
@mesiarm Yes I am aware of that but this isn't permanent, I still want timestamps, just not certain times (such as a migration) when mass updating.
You can also disable it only in certain times as folows:
$object->timestamps = false;
$object->save();
@mesiarm Yes but in the case of mass updates this is not an option. e.g
Article::update([
'foo' => 'bar'
]);
Just use a DB call then and don't use Eloquent
@Sladewill Using DB isn't cleaner because it doesnt return the records, only the number of affected rows, plus you have to specify the table too. A simple option to specify that we want to do a silent update would be good.
Currently i have this code:
DB::table('simulations')
->where('id', $simulation->id)
->update(['is_sample' => ! $simulation->is_sample]);
would be better if i could do the same like this:
$simulation->silentUpdate(
['is_sample' => ! $simulation->is_sample]
);
Looking to make a mass update on a model for a new flag I'm adding to the table but don't want to touch the
updated_at
timestamp. I recall long ago (5.8?) theupdate
method supported a second parameter that one could pass an array such as['timestamps' => false]
to to avoid touching the timestamps.It could look something like a new method
updateNoTouch()
or even checking fortimestamps
value in the$values
array and iffalse
then to not call$this->addUpdatedAtColumn($values)
.A workaround currently is to just call
Model::toBase()->update(['foo' => 'bar'])