laravel-model-logger maintained by peters-development
Description
Lightweight polymorphic model activity logging for Laravel.
Author
Last update
2026/05/27 03:11
(dev-main)
License
Downloads
4
Laravel Model Logger
Lightweight polymorphic model activity logging for Laravel.
Installation
composer require peters-development/laravel-model-logger
The service provider is auto-discovered. Migrations run automatically.
Usage
Add the HasModelLogs trait to any Eloquent model:
use PetersDevelopment\ModelLogger\HasModelLogs;
class Order extends Model
{
use HasModelLogs;
}
Then log activity:
$order->log('Order was shipped');
$order->log('Payment received', ['amount' => 99.99, 'method' => 'ideal']);
// Retrieve logs
$order->logs; // Collection of ModelLog
The authenticated user is automatically recorded. Meta data is stored as JSON.
The log() method returns the created ModelLog instance:
$log = $order->log('Status changed', ['from' => 'pending', 'to' => 'shipped']);
Querying Logs
Access the user that performed the action:
$log->user; // Returns the User model
Filter logs by user:
use PetersDevelopment\ModelLogger\ModelLog;
$logs = ModelLog::forUser($userId)->get();
Configuration
Publish the config to customize the table name:
php artisan vendor:publish --tag=model-logger-config
// config/model-logger.php
return [
'table_name' => 'model_logs',
];
License
MIT