Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Activitylog Laravel Package

spatie/laravel-activitylog

Log user and model activity in Laravel with a simple API. Automatically record Eloquent model events, link actions to subjects and causers, store custom properties, and query a dedicated activity_log table for auditing and history.

View on GitHub
Deep Wiki
Context7

title: Define causer for runtime weight: 4

In many cases you may want to set the causer for a block of code, for example inside jobs where there's no logged-in user. The Activity facade provides defaultCauser() for this.

Scoped causer

Pass a callback as the second argument to scope the causer to that block. The previous causer is automatically restored afterwards:

use Spatie\Activitylog\Facades\Activity;

Activity::defaultCauser($admin, function () {
    $product->update(['name' => 'New name']);
    // this activity will have $admin as the causer
});

// the previous causer is restored here

This works cleanly in jobs, CLI commands, seeders, and multi-guard setups.

Global causer

Without a callback, the causer is set for the rest of the request:

use Spatie\Activitylog\Facades\Activity;

Activity::defaultCauser($admin);

$product->update(['name' => 'New name']);

\Spatie\Activitylog\Models\Activity::all()->last()->causer; // $admin
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
codraw/framework-extra-bundle
codraw/messenger
codraw/security
codraw/mailer
codraw/contracts
codraw/profiling
codraw/dependency-injection
codraw/tester
codraw/core
nexmo/api-specification
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony