garcia1901l/laravel-activity-lite
Lightweight MongoDB-backed activity logger for Laravel (7–12). Automatically tracks model create/update/delete, records the causer (user, artisan, queues), supports manual log entries, configurable events, and powerful querying with CLI filters and JSON/CSV export.
Lightweight activity logger for Laravel using MongoDB (Laravel 10–12 compatible).
El paquete es compatible con estas versiones del driver oficial:
mongodb/laravel-mongodb: 3.8+ (incluye v4 y v5)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"
php artisan activity-lite:install
This will:
Add the trait to your models:
use Garcia1901l\LaravelActivityLite\Traits\LogsActivity;
use Illuminate\Database\Eloquent\Model;
class User extends Model
{
use LogsActivity;
}
User::logManualAction('custom_action', [
'message' => 'Special event occurred',
'data' => ['key' => 'value']
]);
# 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
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
];
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 |
config(['activity-lite.enabled' => false]);
'except' => [
App\Models\SensitiveModel::class,
],
public function getActivityLogOptions(): array
{
return [
'log_attributes' => ['name', 'email'],
'ignore_attributes' => ['password', 'remember_token']
];
}
MIT License. See LICENSE for details.
Frank Garcia
How can I help you explore Laravel packages today?