madhurasri / laravel-activitylog-mongodb
This is an extended version of the popular spatie/laravel-activitylog package designed to store data in MongoDB databases.
Fund package maintenance!
spatie
spatie.be/open-source/support-us
Requires
- php: ^8.0
- illuminate/config: ^8.0 || ^9.0
- illuminate/database: ^8.69 || ^9.27
- illuminate/support: ^8.0 || ^9.0
- jenssegers/mongodb: *
- spatie/laravel-package-tools: ^1.6.3
Requires (Dev)
- ext-json: *
- orchestra/testbench: ^6.23 || ^7.0
- pestphp/pest: ^1.20
README
Log activity inside your Laravel app with MongoDB support
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.