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: Log Options weight: 10

Customization of how your models will be logged is controlled by implementing getActivitylogOptions(). This method is optional. If not implemented, the package uses sensible defaults (logs events but no attribute changes).

The most basic example of an Activity logged model is:

use Illuminate\Database\Eloquent\Model;
use Spatie\Activitylog\Models\Concerns\LogsActivity;

class YourModel extends Model
{
    use LogsActivity;
}

To customize what gets logged, override getActivitylogOptions():

use Illuminate\Database\Eloquent\Model;
use Spatie\Activitylog\Models\Concerns\LogsActivity;
use Spatie\Activitylog\Support\LogOptions;

class YourModel extends Model
{
    use LogsActivity;

    public function getActivitylogOptions(): LogOptions
    {
        return LogOptions::defaults()
        ->logFillable()
        ->logOnlyDirty();
    }
}

The call to LogOptions::defaults() yields the following default options:

public ?string $logName = null;

public bool $logEmptyChanges = true;

public bool $logFillable = false;

public bool $logOnlyDirty = false;

public bool $logUnguarded = false;

public array $logAttributes = [];

public array $logExceptAttributes = [];

public array $dontLogIfAttributesChangedOnly = [];

public array $attributeRawValues = [];

public ?Closure $descriptionForEvent = null;

Options methods

defaults

/**
 * Start configuring model with the default options.
 */
public static function defaults(): LogOptions;

logAll

This method is equivalent to ->logOnly(['*']).

/**
 * Log all attributes on the model.
 */
public function logAll(): LogOptions;

logUnguarded

/**
 * Log changes to all attributes that are not listed in $guarded.
 */
public function logUnguarded(): LogOptions;

This can be combined with ->logFillable() or ->logOnly(). The final set of logged attributes is the union of all sources.

logFillable

/**
 * Log changes to all the $fillable attributes of the model.
 */
public function logFillable(): LogOptions;

This can be combined with ->logUnguarded() or ->logOnly(). The final set of logged attributes is the union of all sources.

dontLogFillable

/**
 * Stop logging $fillable attributes of the model.
 */
public function dontLogFillable(): LogOptions;

logOnlyDirty

/**
 * Log changes that have actually changed after the update.
 */
public function logOnlyDirty(): LogOptions;

logOnly

/**
 * Only log changes to these specific attributes.
 */
public function logOnly(array $attributes): LogOptions;

logExcept

Convenient method for excluding specific attributes from logging.

/**
 * Exclude these attributes from being logged.
 */
public function logExcept(array $attributes): LogOptions;

dontLogIfAttributesChangedOnly

/**
 * Don't trigger an activity if only these attributes changed.
 */
public function dontLogIfAttributesChangedOnly(array $attributes): LogOptions;

dontLogEmptyChanges

/**
 * Don't store empty logs. Empty logs can occur when you're tracking
 * specific attributes but none of them actually changed.
 */
public function dontLogEmptyChanges(): LogOptions;

logEmptyChanges

/**
 * Allow storing empty logs.
 */
public function logEmptyChanges(): LogOptions;

useLogName

/**
 * Customize log name.
 */
public function useLogName(string $logName): LogOptions;

useAttributeRawValues

/**
 * Skip using mutators for these attributes when logged.
 */
public function useAttributeRawValues(array $attributes): LogOptions;

setDescriptionForEvent

/**
 * Customize log description using callback.
 */
public function setDescriptionForEvent(Closure $callback): LogOptions;
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