garcia1901l/laravel-activity-lite
最新稳定版本:2.0.1
Composer 安装命令:
composer require garcia1901l/laravel-activity-lite
包简介
Lightweight activity logger for Laravel
README 文档
README
Lightweight activity logger for Laravel using MongoDB (Laravel 10–12 compatible).
✨ Features
- 🚀 Automatic model activity tracking (create/update/delete)
- 🔍 MongoDB database for lightweight operation
- 👤 Tracks causer (user, artisan, queue jobs)
- ⚡ Configurable event logging
- 📊 Powerful querying capabilities
- 📦 Easy installation and setup
Requisitos de MongoDB
El paquete es compatible con estas versiones del driver oficial:
mongodb/laravel-mongodb: 3.8+ (incluye v4 y v5)- PHP extension
mongodb: 1.10+
Si necesitas usar una versión diferente, instálala manualmente:
composer require mongodb/laravel-mongodb:"YOUR_VERSION" ## 📦 Installation ### 1. Install via Composer ```bash composer require garcia1901l/laravel-activity-lite
Optional: Publish the configuration file:
php artisan vendor:publish --provider="Garcia1901l\LaravelActivityLite\ActivityLiteServiceProvider"
2. Run the installation command
php artisan activity-lite:install
This will:
- Create the MongoDB database
- Run the required migrations
🧑💻 Basic Usage
Add the trait to your models:
use Garcia1901l\LaravelActivityLite\Traits\LogsActivity; use Illuminate\Database\Eloquent\Model; class User extends Model { use LogsActivity; }
🔧 Advanced Usage
Manual Logging
User::logManualAction('custom_action', [ 'message' => 'Special event occurred', 'data' => ['key' => 'value'] ]);
Query Logs
# View recent activity php artisan activity-lite:query --days=7 # Filter by model php artisan activity-lite:query --model=User # Filter by action php artisan activity-lite:query --action=updated # Export results php artisan activity-lite:query --days=30 --json php artisan activity-lite:query --days=30 --csv
⚙️ Configuration
Publish the config file:
php artisan vendor:publish --tag=activity-lite-config
Example of config/activity-lite.php:
return [ 'enabled' => true, 'database_name' => 'activity_lite', 'events' => ['created', 'updated', 'deleted', 'soft_deleted', 'force_deleted', 'restored'], 'except' => [], // Models to exclude ];
🗃️ Database Structure
The activity_logs table includes:
| Column | Type | Description |
|---|---|---|
| id | bigint | Primary key |
| action | string | Performed action |
| log_type | string | 'model' or 'manual' |
| model_type | string | Model class |
| model_id | bigint | Model ID |
| causer_type | string | Who performed the action |
| causer_id | bigint | Causer ID |
| data | json | Change data |
| created_at | timestamp | Creation time |
| updated_at | timestamp | Last update time |
🛠️ Customization
Temporarily disable logging
config(['activity-lite.enabled' => false]);
Exclude specific models
'except' => [ App\Models\SensitiveModel::class, ],
Log only specific attributes and ignore others
public function getActivityLogOptions(): array { return [ 'log_attributes' => ['name', 'email'], 'ignore_attributes' => ['password', 'remember_token'] ]; }
✅ Requirements
- PHP 8.1+
- Laravel 10.x to 12.x
- MongoDB extension for PHP
📄 License
MIT License. See LICENSE for details.
👤 Author
Frank Garcia
统计信息
- 总下载量: 3
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-04-09