Skip to content

Instantly share code, notes, and snippets.

@grim-reapper
Forked from janzikmund/SaveQuietly.php
Created May 15, 2020 17:29
Show Gist options
  • Select an option

  • Save grim-reapper/2edcc410e70a0a97b91ae2c55fae9e89 to your computer and use it in GitHub Desktop.

Select an option

Save grim-reapper/2edcc410e70a0a97b91ae2c55fae9e89 to your computer and use it in GitHub Desktop.
Laravel eloquent trait to add method for save model without triggering observers
<?php
namespace App\Traits;
/**
* Allows saving models without triggering observers
*/
trait SaveQuietly
{
/**
* Save model without triggering observers on model
*/
public function saveQuietly(array $options = [])
{
return static::withoutEvents(function () use ($options) {
return $this->save($options);
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment