devel8/laravel-action-tracker
Track and query an audit history of actions performed on Eloquent models. Add a trait, define allowed actions, record actions with messages, fetch per-model action logs, and dispatch generic or per-action events for listeners and custom workflows.
Model::saved, Model::deleted, etc.) to log actions, aligning well with Laravel’s built-in event architecture. This ensures minimal intrusion into existing business logic.User, Order) and expand later.config/action-tracker.php and observer bindings.LogApiAction) to track non-model actions (e.g., API calls).Monolog), caching (e.g., action_tracker:recent), and query builder for filtering tracked actions.updated_at auto-updates).ActionTracker::batch()).action_tracker:recent).Order::paid)?ip_address, user_agent) per action?actions, action_types, actionable_models).action_tracker:recent and similar commands.ActionTracker::queue()) for async logging.composer require devel8/laravel-action-tracker.config/action-tracker.php (e.g., default action types, table names).User, Invoice).php artisan action-tracker:list and action-tracker:recent.registerModelForActionTracking().order.shipped, user.suspended) in migrations.actions table for common queries (e.g., actionable_type, action_type, created_at).action_tracker:recent (e.g., Redis).fraud.detected).spatie/laravel-activitylog).ActionTracker::extend()).BaseObserver.php artisan vendor:publish).| Step | Task | Dependencies | Tools/Commands |
|---|---|---|---|
| 1 | Install & Configure | Laravel app | composer require, php artisan config:publish |
| 2 | Define Action Types | DB schema | Migration, php artisan migrate |
| 3 | Bind Observers | Model classes | registerModelForActionTracking() |
| 4 | Test Basic Tracking | Events fired | php artisan tinker, Action::all() |
| 5 | Optimize Queries | Indexes | php artisan schema:dump |
| 6 | Add Caching | Redis/Memcached | config/cache.php |
| 7 | Queue Non-Critical | Async logging | ActionTracker::queue() |
| 8 | Extend for Analytics | Third-party integrations | Custom listeners, webhooks |
devel8/laravel-action-tracker for breaking changes (e.g., Laravel 10 compatibility).try-catch in observers).action_tracker table for missing entries (observer not bound?).php artisan event:list to verify event listeners.DB::enableQueryLog()) for slow queries.saved, deleted) are fired.Action::truncate()).actions table by created_at (e.g., monthly) or use read replicas.user.login).action_tracker:recent) with TTLs.| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Database Downtime | Lost actions if not queued | Use queue + dead-letter queue for retries. |
| Observer Errors | Silent failures if uncaught | Wrap observer logic in try-catch + log errors. |
| Schema Mismatch | Query failures | Use migrations + CI checks (e.g., php artisan migrate:status). |
| Queue Backlog | Delayed actions | Monitor queue length; scale consumers. |
| Permission Issues | Logs not writable | Ensure storage/logs and DB have correct permissions. |
CONTRIBUTING.md.How can I help you explore Laravel packages today?