Reputation: 161
I am interested if there is a difference between saving the model using withoutEvents
and saveQuietly
. What is the main difference between next two pieces of code:
$user = User::withoutEvents(function () use () {
$user = User::findOrFail(1);
$user->name = 'Victoria Faith';
$user->save();
return $user;
});
and:
$user = User::findOrFail(1);
$user->name = 'Victoria Faith';
$user->saveQuietly();
Upvotes: 7
Views: 9599
Reputation: 4275
SaveQuietly
is a wrapper for the closure WithoutEvents
that accepts options:
trait SaveQuietly
{
/**
* Save model without triggering observers on model
*/
public function saveQuietly(array $options = [])
{
return static::withoutEvents(function () use ($options) {
return $this->save($options);
});
}
}
Upvotes: 15