The spatie/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. All activity will be stored in the activity_log table.
Here's a little demo of how you can use it:
activity()->log('Look mum, I logged something');
You can retrieve all activity using the Spatie\Activitylog\Models\Activity model.
Activity::all();
Here's a more advanced example:
activity()
->performedOn($anEloquentModel)
->causedBy($user)
->withProperties(['customProperty' => 'customValue'])
->log('Look mum, I logged something');
$lastLoggedActivity = Activity::all()->last();
$lastLoggedActivity->subject;
$lastLoggedActivity->causer;
$lastLoggedActivity->getProperty('customProperty');
$lastLoggedActivity->description;
Here's an example on event logging.
$newsItem->name = 'updated name';
$newsItem->save();
$activity = Activity::all()->last();
$activity->description;
$activity->subject;
Calling $activity->attribute_changes will return this collection:
[
'attributes' => [
'name' => 'updated name',
'text' => 'Lorem',
],
'old' => [
'name' => 'original name',
'text' => 'Lorem',
],
];
##We have badges!