How luissantiago/elogquent works
Project Type and Purpose
• This is a Laravel package (“Elogquent”) that plugs into any Laravel application to automatically audit all changes to Eloquent models, store them in a dedicated table, and allow restorations.
• It provides an Observer-based change‐tracking system, queue‐based job processing, a repository for data access, and artisan commands for installation and change restoration.
Main Components
a. Host Laravel Application (the “consumer”)
• Bootstraps the package via ElogquentServiceProvider
• Holds user models that “use Elogquent” trait
b. Elogquent Package Core
• Service Provider (registers Observer, Commands, Config)
• Trait (Elogquent) that attaches Observer to model events
• Observer (ElogquentObserver) that listens to model events and dispatches Jobs
• Jobs (ProcessCreateEntry, ProcessRemoveDuplicates, ProcessClearExceededLimit, ProcessRestoreChanges)
• Repository (contract + ElogquentDatabaseRepository) implementing data‐access logic
• Model (ElogquentEntry) representing the audit‐trail table
• Artisan Commands (install, restore)
• Configuration (config/elogquent.php)
c. Infrastructure
• Database (change history table, migrations)
• Laravel Queue (driver, connection, queue name)
Component Relationships & Data Flows
1. At runtime, any Eloquent model using the Elogquent trait emits “created/updated/deleted” events.
2. ElogquentObserver catches these events and packages them into Jobs.
3. Jobs are dispatched to the Laravel Queue.
4. Queue Worker picks up jobs and invokes the Repository to write/read the ElogquentEntry table.
5. Restore command or restore‐job fetches historical data via the Repository and updates the target model to a previous state.
Architectural Patterns & Design Principles
• Observer pattern: separating change‐detection logic from models
• Command pattern: encapsulating install/restore logic as artisan commands
• Repository pattern: abstracting database I/O behind an interface
• Queue‐based asynchronous processing for non‐blocking model operations
• Trait‐based mixin to keep models free of boilerplate
• Configurable via a config/elogquent.php file following Laravel conventions
Detailed Element Checklist
• Each component must be individually boxed and clearly named
• How the artisan commands hook into the ServiceProvider