Closed derekmd closed 5 months ago
You can but that will also prevent other event listeners from being invoked. This method would allow only disabling audit callbacks.
Could someone please update the documentation? You could follow the idea from the Laravel documentation.
@derekmd would you like the honours? https://github.com/owen-it/laravel-auditing.com/ perhaps something under the advanced section?
@derekmd hi, this give me test errors: https://github.com/owen-it/laravel-auditing/actions/runs/9256833548
$result = Article::withoutAuditing(function () {
$this->assertTrue(Article::$auditingDisabled);
$this->assertFalse(ArticleExcludes::$auditingDisabled); //here, is true instead of false, why?
@erikn69: https://github.com/owen-it/laravel-auditing/commit/a08c673e31bc4d55b6f5b5dd8cc9ab9085022d15#diff-a23c87e87a036f61cc6c88f12299ba20cfbbc59b4a825ee48689ee701aeace25L5 merged after I opened this PR changed test stub ArticleExcludes extends Article
so the two classes now share the same static $auditingDisabled
state.
Thanks, I already noticed it, #937
maybe another idea, globally disable audits on all models within the callback block, maybe it could be done with a second argument
Summary
Similar to Laravel's
Model::withoutEvents()
method, allow running Eloquent queries on a given model class inside a callback:Only the
{class}::withoutAuditing()
class will have auditing disabled, so additional model classes need their own call. e.g.,try
/finally
to handle restoring auditing after Eloquent possibly throwsQueryException
.enableAuditing()
Links