rashidsiaghi/laravel-activitylog

Custom activity log system based on Spatie Laravel Activitylog

1.0.1 2025-06-11 23:41 UTC

This package is auto-updated.

Last update: 2025-06-12 00:06:11 UTC


README

This package is a customized activity logging system for Laravel, extending and modifying the excellent Spatie Laravel Activitylog.

✅ Features

  • Logs model attributes, including nested and relationship changes.
  • Adds tracking for device info, IP address, browser, and user role.
  • Customizable pipelines and event descriptions.
  • Built-in support for hasMany, belongsToMany, and morphMany relationships.

📦 Based On

Log activity inside your Laravel app

Latest Version on Packagist GitHub Workflow Status Check & fix styling Total Downloads

The rashidsiaghi/laravel-activitylog package provides easy to use functions to log the activities of the users of your app. It can also automatically log model events. The Package stores all activity in the activity_log table.

Here's a demo of how you can use it:

activity()->log('Look, I logged something');

You can retrieve all activity using the rashidsiaghi\Activitylog\Models\Activity model.

Activity::all();

Here's a more advanced example:

activity()
   ->performedOn($anEloquentModel)
   ->causedBy($user)
   ->withProperties(['customProperty' => 'customValue'])
   ->log('Look, I logged something');

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

$lastLoggedActivity->subject; //returns an instance of an eloquent model
$lastLoggedActivity->causer; //returns an instance of your user model
$lastLoggedActivity->getExtraProperty('customProperty'); //returns 'customValue'
$lastLoggedActivity->description; //returns 'Look, I logged something'

Here's an example on event logging.

$newsItem->name = 'updated name';
$newsItem->save();

//updating the newsItem will cause the logging of an activity
$activity = Activity::all()->last();

$activity->description; //returns 'updated'
$activity->subject; //returns the instance of NewsItem that was saved

Calling $activity->changes() will return this array:

[
   'attributes' => [
        'name' => 'updated name',
        'text' => 'Lorum',
    ],
    'old' => [
        'name' => 'original name',
        'text' => 'Lorum',
    ],
];

Attribution

This activity logging system is based on rashidsiaghi Laravel Activitylog, released under the MIT License.
Modifications have been made to support relationship logging, trait extension, and additional device/user context features.

This code is derived from and heavily inspired by spatie/laravel-activitylog, originally created by Spatie.

We thank the Spatie team for their excellent work, which serves as the foundation of this customized version.

Installation

You can install the package via composer:

composer require rashidsiaghi/laravel-activitylog

The package will automatically register itself.

You can publish the migration with:

php artisan vendor:publish --provider="RashidSiaghi\Activitylog\ActivitylogServiceProvider" --tag="activitylog-migrations"

Note: The default migration assumes you are using integers for your model IDs. If you are using UUIDs, or some other format, adjust the format of the subject_id and causer_id fields in the published migration before continuing.

After publishing the migration you can create the activity_log table by running the migrations:

php artisan migrate

You can optionally publish the config file with:

php artisan vendor:publish --provider="RashidSiaghi\Activitylog\ActivitylogServiceProvider" --tag="activitylog-config"

Changelog

Please see CHANGELOG for more information about recent changes.

Upgrading

Please see UPGRADING for details.

Testing

composer test

Contributing

Please see CONTRIBUTING for details.

🔒 License

This project and all modified code are released under the MIT License.
Original copyright © Spatie.