ascend/laravel-column-watcher
Attribute-based “column watchers” for Laravel Eloquent models. Trigger handlers only when specific attributes change (before/after save), with support for multiple watchers, queueable handlers, events, and Octane compatibility—avoiding bulky, monolithic model observers.
updated_at, custom metadata).status, price) change.beforeSave/afterSave hooks enable pre-validation or post-processing logic.price changes, ensure tax_rate is valid")? This package handles single-column triggers.afterSave queue jobs vs. synchronous handlers?saved()/updating() events?ColumnChange objects may be necessary.afterSave).observing(User::class) → [User::class, 'email']).UserObserver::updating(User $user) → After:
#[Watcher(columns: ['email'])]
class UpdateEmailHandler {
public function handle(ColumnChange $change): void { ... }
}
#[Watcher(timing: Timing::BEFORE_SAVE)] for pre-processing.deleting()) until fully migrated.saving()/updating(). Test with:
composer require ascend/laravel-column-watcher.config/app.php (autoloads attributes).ColumnChange mocks.failed_jobs table).app/Models/User/Handlers/).dd($change) in handlers to inspect ColumnChange objects (old/new values, model instance).tap() for debugging:
$change->tap(fn($c) => tap($c->model)->forceFill(['debug' => true]));
user->update(['email' => $change->newValue])).failed_jobs for handler exceptions.ColumnChange payloads.beforeSave handlers (use queues for afterSave).Model::where(...)->update()).| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Handler throws exception | Transaction rollback (if in beforeSave). |
Use try-catch in handlers; log errors. |
| Queue worker crashes | Async handlers fail silently. | Enable queue monitoring (Horizon). |
| Circular dependency | Infinite loop on column updates. | Add #[Watcher(protection: true)] (built-in). |
| Attribute parsing error | Model initialization fails. | Validate PHP version/attributes in CI. |
| Mass assignment bypasses watch | Unwatched columns updated. | Use $model->fill() instead of update(). |
ColumnChange object structure.beforeSave/afterSave timing and edge cases.if (price > 1000 && status === 'active')).php artisan column-watcher:list
How can I help you explore Laravel packages today?