Skip to content

Instantly share code, notes, and snippets.

@janzikmund
Created December 11, 2019 03:35
Show Gist options
  • Save janzikmund/b608b72bcf42e4e534423bba1e3ed919 to your computer and use it in GitHub Desktop.
Save janzikmund/b608b72bcf42e4e534423bba1e3ed919 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