Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add withoutAuditing() callback method to temporarily disable auditing for one class #917

Merged
merged 1 commit into from
May 27, 2024

Commits on Mar 21, 2024

  1. Add withoutAuditing() for callbacks

    Similar to Laravel's Model::withoutEvents() method,
    allow running Eloquent queries on a given model class
    inside a Closure.
    
    User::withoutAuditing(function () use ($user, $inputs, $additional) {
        // no audit
        $user->update($inputs);
    
        // this _will_ be audited if the Profile class is Auditable
        $user->profiles()->updateOrCreate([], $additional);
    });
    
    Nest model class calls to disable auditing for many classes:
    
    User::withoutAuditing(fn () => $user->update($inputs));
    Profile::withoutAuditing(fn () => $user->profiles()->updateOrCreate([], $additional));
    derekmd committed Mar 21, 2024
    Configuration menu
    Copy the full SHA
    941480d View commit details
    Browse the repository at this point in the history