A Laravel package for logging user activity with admin and user views
escarter/activity-log is a Laravel package for a laravel package for logging user activity with admin and user views.
It currently has 1 GitHub stars and 6 downloads on Packagist (latest version 1.0.1.0).
Install it with composer require escarter/activity-log.
Discover more Laravel packages by escarter
or browse all Laravel packages to compare alternatives.
Last updated
A comprehensive Laravel package for logging and tracking user activity in your application.
You can install the package via composer:
composer require escarter/activity-log
Publish the config file:
php artisan vendor:publish --tag=activity-log-config
Publish the migrations:
php artisan vendor:publish --tag=activity-log-migrations
Publish the views (optional):
php artisan vendor:publish --tag=activity-log-views
Run the migrations:
php artisan migrate
To track changes to a model, add the LogsActivity trait to the model:
use Escarter\ActivityLog\Traits\LogsActivity;
use Illuminate\Database\Eloquent\Model;
class Post extends Model
{
use LogsActivity;
// Optional: customize which events to log
public function shouldLogActivity(string $event): bool
{
// Only log creates and updates
return in_array($event, ['created', 'updated']);
}
}
You can manually log activities:
use Escarter\ActivityLog\ActivityLogFacade as ActivityLog;
use Escarter\ActivityLog\DTOs\ActivityLogData;
// Using facade
ActivityLog::log(new ActivityLogData(
logName: 'orders',
description: 'Order was shipped',
subject: $order,
causer: auth()->user(),
event: 'shipped'
));
// Log model events
ActivityLog::logModel($model, 'archived', auth()->user());
// Log user login
ActivityLog::logLogin($user);
The package includes Livewire components for displaying activity logs:
// In your routes/web.php
Route::middleware(['auth', 'admin'])->group(function () {
Route::get('/admin/activity-logs', function () {
return view('activity-log::livewire.admin-activity-log');
})->name('admin.activity-logs');
});
// In your routes/web.php
Route::middleware(['auth'])->group(function () {
Route::get('/my-activity', function () {
return view('activity-log::livewire.user-activity-log');
})->name('user.activity-logs');
});
You can clean old logs using the provided command:
php artisan activity-log:clean --days=30
Or you can schedule it in your App\Console\Kernel:
protected function schedule(Schedule $schedule)
{
$schedule->command('activity-log:clean')->daily();
}
The MIT License (MIT). Please see License File for more information.