imbrett / laravel-listener-attributes
Attribute-driven event listener registration for Laravel.
Package info
github.com/ImBrett/laravel-listener-attributes
pkg:composer/imbrett/laravel-listener-attributes
v1.1.0
2026-11-06 03:21 UTC
Requires
- php: ^8.2
- illuminate/container: ^11.0|^12.0|^13.0
- illuminate/events: ^11.0|^12.0|^13.0
- illuminate/support: ^11.0|^12.0|^13.0
Requires (Dev)
- orchestra/testbench: ^9.0|^10.0|^11.0
- roave/security-advisories: dev-latest
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Tiny helper that lets you register event listeners in Laravel using PHP attributes instead of manual service provider wiring.
Features
#[ListensTo(Event::class)]attribute for listener methods.- Service provider scans configured subscriber classes and registers them with the event dispatcher.
- Works with container-resolved listeners and repeatable attributes.
Installation
composer require imbrett/laravel-listener-attributes
Usage
- Configure your subscriber classes (e.g. in
config/listener-attributes.php):
return [ 'subscribers' => [ \App\Listeners\AuthSubscriber::class, ], ];
- Annotate listener methods:
use ImBrett\LaravelListenerAttributes\Attributes\ListensTo; class AuthSubscriber { #[ListensTo(UserLoggedIn::class)] public function onLogin(UserLoggedIn $event): void { // ... } }
The service provider will discover those methods at boot and call $dispatcher->listen() for you. Listeners are registered using the standard [$class, $method] signature so they benefit from container resolution on every dispatch.
Configuration
Publish and edit the default configuration:
php artisan vendor:publish --tag=listener-attributes-config
Testing
make test TEST_ARGS="--testsuite=ListenerAttributes"
Documentation
docs/index.md– documentation table of contents.docs/getting-started.md– configuration and attribute usage.docs/advanced.md– repeatable attributes, conditional registration, and queueing.docs/testing.md– asserting registrations and debugging.- Register custom attributes at runtime via the
AttributeRegistryor list them underlistener-attributes.attributes.
License
MIT © Brett