mohit-hasan/laravel-activity-logger
最新稳定版本:v1.0.0
Composer 安装命令:
composer require mohit-hasan/laravel-activity-logger
包简介
A reusable Laravel package to automatically track and log user actions across the app.
README 文档
README
A Laravel package that automatically logs Eloquent model events (create/update/delete) and supports manual logging with metadata, polymorphic relationships, and auto-capture of user/IP/user agent.
Live Demo: https://activity-logger.mohithasan.com
Run Demo Locally
git clone https://github.com/mohit-hasan/laravel-activity-logger.git
cd laravel-activity-logger/demo
cp .env.example .env
composer install
php artisan key:generate
php artisan migrate --seed
php artisan serve
Visit http://localhost:8000. Use the buttons to test: Manual Log, Create Post, Update Post, Delete Post. All entries appear in the table with action, description, model link, user, IP, metadata, and timestamp.
Install in Your App
composer require mohit-hasan/laravel-activity-logger dev-main
php artisan vendor:publish --provider="MohitHasan\ActivityLogger\ActivityLoggerServiceProvider"
php artisan migrate
Auto-discovers service provider and facade — no manual registration needed.
Usage
Trait — Auto-log model events
use MohitHasan\ActivityLogger\Traits\LogsActivity; class Post extends Model { use LogsActivity; }
Every created, updated, deleted on Post is logged automatically.
Facade — Manual logging
use MohitHasan\ActivityLogger\Facades\ActivityLogger; ActivityLogger::action('user_login') ->description('User logged in.') ->log();
With metadata
ActivityLogger::action('order_placed') ->description('Order placed.') ->with(['order_id' => 12345, 'total' => 99.99]) ->log();
Link to a model (polymorphic)
ActivityLogger::action('post_published') ->on($post) ->log();
Retrieve logs
$logs = ActivityLogger::getAll(); // all $logs = ActivityLogger::getAll(action: 'created'); // filtered $logs = ActivityLogger::getAll(for: $post); // for a model
All methods chain: action() → description() → on() → with() → by() → log(). Returns null silently on failure — never throws.
Fluent API (full chain)
$log = ActivityLogger::action('export') ->description('User exported report') ->on($report) ->with(['format' => 'PDF', 'rows' => 500]) ->by($userId) ->log();
All methods chain. Returns null silently on failure — never throws.
Config (config/activity-logger.php)
| Key | Default | Description |
|---|---|---|
table_name |
activity_logs |
DB table name |
user_model |
App\Models\User |
User model class |
capture_fields |
['ip_address' => true, 'user_agent' => true] |
Auto-capture toggles |
ignore_events |
['retrieved'] |
Events to skip |
log_events |
['created', 'updated', 'deleted', 'restored'] |
Events to track |
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 14
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-05-14