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: Using multiple logs weight: 5

The default log

Without specifying a log name, the activities will be logged on the default log.

activity()->log('hi');

$lastActivity = Activity::all()->last();

$lastActivity->log_name; //returns 'default';

You can specify the name of the default log in the default_log_name key of the config file.

Specifying a log

You can specify the log on which an activity must be logged by passing the log name to the activity function:

activity('other-log')->log("hi");

Activity::all()->last()->log_name; //returns 'other-log';

Specifying a log for each model

By default, the LogsActivity trait uses default_log_name from the config file to write the logs. To customize the log's name for each model, call the useLogName() method when configuring the LogOptions.

public function getActivitylogOptions(): LogOptions
{
    return LogOptions::defaults()
        ->useLogName('custom_log_name_for_this_model');
}

Retrieving activity

The Activity model is just a regular Eloquent model that you know and love:

Activity::where('log_name', 'other-log')->get(); //returns all activity from the 'other-log'

There's also an inLog scope you can use:

Activity::inLog('other-log')->get();

//you can pass multiple log names to the scope
Activity::inLog('default', 'other-log')->get();

//passing an array is just as good
Activity::inLog(['default', 'other-log'])->get();
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