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.
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"
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',
],
];
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.
composer test
Please see CHANGELOG for more information about recent changes.
And a special thanks to Caneco for the logo and Ahmed Nagi for all the work he put in v4
.
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.
The MIT License (MIT). Please see License File for more information.