- What does softonic/laravel-transactional-event-publisher do?
- It is a Laravel package that defers dispatching domain events until the surrounding database transaction commits. This prevents listeners from reacting to data that may still be rolled back and helps keep events consistent with persisted state.
- How do I install softonic/laravel-transactional-event-publisher in Laravel?
- Install it with Composer using composer require softonic/laravel-transactional-event-publisher. Laravel package discovery should register the service provider automatically; publish and adjust any configuration only if the repository README instructs you to.
- Which Laravel and PHP versions does this package support?
- Supported Laravel and PHP versions are defined in the package's composer.json and Packagist metadata. Check the repository README and release notes before upgrading, because constraints can change between major versions.
- What happens if the database transaction rolls back?
- When a transaction rolls back, deferred events tied to that transaction are not published. That avoids listeners seeing changes that were never persisted. Confirm the exact rollback behavior for nested transactions in the README.
- Does it work with Laravel queued listeners and jobs?
- Yes, once the event is published after commit, normal Laravel queued listeners and jobs can handle it as usual. The key benefit is that queued work is not dispatched for uncommitted or rolled-back data.
- Can I use it with multiple database connections or nested transactions?
- Multi-connection and nested transaction behavior depends on how your application opens transactions and how the package is configured. Review the README for supported connection handling before relying on it in complex transaction flows.
- How do I test that events are published only after commit?
- Use Laravel's Event::fake or a real listener spy, open a transaction, fire the event, and assert it is not handled before commit. Then commit and assert the listener runs; also test rollback to confirm no event is published.
- Is this package a replacement for Laravel's event dispatcher or after-commit callbacks?
- It is not a wholesale replacement for Laravel's event dispatcher; it adds transactional deferral around event publishing. Laravel also offers mechanisms such as ShouldHandleEventsAfterCommit and after-commit callbacks, so compare fit and maintenance before choosing.
- What are the production considerations for transactional event publishing?
- Keep transactions short, because events wait until commit and long transactions delay listener work. Remember that after-commit listener failures cannot roll back the already committed database changes, so add monitoring and idempotency where needed.
- What alternatives exist to this package for Laravel transactional events?
- Alternatives include Laravel's ShouldHandleEventsAfterCommit interface, after-commit callbacks, and transactional outbox patterns for stronger delivery guarantees. Evaluate the package's maintenance status and your consistency requirements before adopting it.