rahad9999 / activitylog
A clean, lightweight activity logging package for Laravel with pure Blade UI, standard Controllers, and REST API support.
Requires
- php: ^8.2|^8.3|^8.4
- illuminate/contracts: ^10.0|^11.0|^12.0|^13.0
- illuminate/database: ^10.0|^11.0|^12.0|^13.0
- illuminate/http: ^10.0|^11.0|^12.0|^13.0
- illuminate/routing: ^10.0|^11.0|^12.0|^13.0
- illuminate/support: ^10.0|^11.0|^12.0|^13.0
- illuminate/view: ^10.0|^11.0|^12.0|^13.0
Requires (Dev)
- orchestra/testbench: ^8.0|^9.0|^10.0|^11.0
- phpunit/phpunit: ^10.0|^11.0|^12.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
A clean, lightweight, and powerful activity logging system for Laravel applications with pure Laravel Blade UI, standard Controllers (no Livewire required), and a full RESTful API.
โจ Features
- ๐ฏ Simple & Direct API: Record logs directly with
ActivityLog::record(),ActivityLog::recordCreated(),ActivityLog::recordUpdated(),ActivityLog::recordDeleted(),ActivityLog::recordCustom(), oractivity_log()helper. - โก Auto-Tracking Eloquent Trait: Add
LogsActivitytrait to any Eloquent model to automatically trackcreated,updated(dirty diffs),deleted, andrestoredevents. - ๐ฅ๏ธ Interactive Pure Blade Dashboard: Responsive timeline sidebar with date groups, live search, multi-filter dropdowns, bulk delete, and single log inspection without needing Livewire.
- ๐ Full RESTful API: Built-in endpoints for listing, filtering, inspecting, bulk deleting, and managing date groups for mobile & headless apps. (View API Documentation)
- ๐งน Interactive Clean Artisan Command:
php artisan activitylog:cleanprompts for specific dates or automatically prunes logs older than retention days. - ๐จ Dark / Light Mode: Built-in support for theme switching with Tailwind CSS.
๐ฆ Installation
You can install the package via Composer:
composer require rahad9999/activitylog
Run the interactive installer to publish the configuration and migrations:
php artisan activitylog:install
Or publish them manually:
php artisan vendor:publish --tag="activitylog-config" php artisan vendor:publish --tag="activitylog-migrations" php artisan migrate
โ๏ธ Configuration
The package configuration file is saved at config/activitylog.php:
return [ // Table name 'table_name' => 'activity_logs', // Model class 'model' => \Rahad\ActivityLog\Models\ActivityLog::class, // Global toggle 'enabled' => true, // Automatic retention in days (used by cleaner command) 'delete_records_older_than_days' => 365, // Web UI Settings 'web' => [ 'enabled' => true, 'route_prefix' => 'activity-logs', 'middleware' => ['web', 'auth'], 'layout' => 'activitylog::layouts.blank', 'title' => 'Activity Log', 'per_page' => 20, 'home_url' => '/', ], // REST API Settings 'api' => [ 'enabled' => true, 'route_prefix' => 'api/activity-logs', 'middleware' => ['api'], 'per_page' => 20, ], ];
๐ Usage
1. Direct Static Logging
use Rahad\ActivityLog\Models\ActivityLog; // Generic log ActivityLog::record( title: 'User updated profile', module: 'User', action: 'updated', subject: $user, old: ['email' => 'old@example.com'], new: ['email' => 'new@example.com'], metadata: ['ip_country' => 'US'] ); // Event shortcuts ActivityLog::recordCreated(module: 'Course', subject: $course, new: $course->toArray()); ActivityLog::recordUpdated(module: 'Course', subject: $course, old: $old, new: $new); ActivityLog::recordDeleted(module: 'Course', subject: $course, old: $old); ActivityLog::recordCustom(title: 'User logged in', module: 'Auth', action: 'login');
2. Global Helper Function
// Quick custom log activity_log('Password changed', 'Auth', 'password_change', $user); // Query builder $recentLogs = activity_log()->module('User')->today()->get();
3. Automatic Eloquent Model Tracking
Add the LogsActivity trait to any Eloquent model to automatically track changes:
namespace App\Models; use Illuminate\Database\Eloquent\Model; use Rahad\ActivityLog\Concerns\LogsActivity; class Post extends Model { use LogsActivity; // Optional: customize the module name protected string $activityModule = 'Blog'; // Optional: ignore specific attributes from tracking protected array $activityIgnoredAttributes = ['view_count', 'updated_at']; }
4. Querying Logs on Models
Add the HasActivityLogs trait to your User model:
use Rahad\ActivityLog\Concerns\HasActivityLogs; class User extends Authenticatable { use HasActivityLogs; } // Access activities performed by this user: $user->activitiesAsCauser; // Access activities where this model was the subject: $post->activitiesAsSubject;
๐งน Cleaning & Pruning Logs
Clean activity logs using the artisan command:
# Interactive mode (prompts to enter a date or use retention policy): php artisan activitylog:clean # Delete logs for a specific date: php artisan activitylog:clean --date=2026-09-15 # Delete logs older than 30 days: php artisan activitylog:clean --days=30 # Force delete without confirmation: php artisan activitylog:clean --date=2026-09-15 --force
๐ Web Dashboard & API
Web Dashboard
Navigate to:
http://your-domain.test/activity-logs
RESTful API
Access JSON endpoints under:
http://your-domain.test/api/activity-logs
For full API endpoint specifications and JSON schema examples, see docs/api.md.
๐งช Testing
composer test
๐ License
The MIT License (MIT). Please see License File for more information.