Created
December 11, 2019 03:35
-
-
Save janzikmund/b608b72bcf42e4e534423bba1e3ed919 to your computer and use it in GitHub Desktop.
Laravel eloquent trait to add method for save model without triggering observers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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