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 events, track subjects and causers, attach custom properties, and query everything via the Activity model. Stores logs in the activity_log table.

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.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport