madhurasri/laravel-activitylog-mongodb

This is an extended version of the popular spatie/laravel-activitylog package designed to store data in MongoDB databases.

1.0.1 2022-12-21 08:48 UTC

This package is auto-updated.

Last update: 2024-11-21 13:31:45 UTC


README

Social Card of Laravel Activity Log

Log activity inside your Laravel app with MongoDB support

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

This is an extended version of the popular spatie/laravel-activitylog package which allows you to easily log activities of your Laravel applications, such as user logins, profile updates, and more. It can also automatically log model events. This extended package allows you to store all activity in a MongoDB collection.

Installation

You can install the package via composer:

composer require madhurasri/laravel-activitylog-mongodb

The package will automatically register itself.

You can publish the config file with:

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

Usage

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

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

You can retrieve all activity using the Madhurasri\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',
    ],
];

Documentation

You'll find the documentation of original package on https://spatie.be/docs/laravel-activitylog/introduction.

Find yourself stuck using the package? Found a bug? Do you have general questions or suggestions for improving the activity log mongodb pakcage? Feel free to create an issue on GitHub, we'll try to address it as soon as possible.

Testing

composer test

Changelog

Please see CHANGELOG for more information about recent changes.

Credits

And a special thanks to Caneco for the logo and Ahmed Nagi for all the work he put in v4.

Support spatie

Spatie invest a lot of resources into creating best in class open source packages. You can support them by buying one of their paid products.

License

The MIT License (MIT). Please see License File for more information.