Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Model Listener

Model Listener Laravel Package

hyperf/model-listener

Hyperf Model Listener adds simple, configurable event listeners to Hyperf's Eloquent-style models. Hook into creating, updating, deleting, and other model lifecycle events to run custom logic cleanly without cluttering your model classes.

Deep Wiki
Context7

hyperf/model-listener brings Laravel-style model event handling to the Hyperf framework. It lets you attach listeners to Eloquent-style model events such as created, updated, and deleted, keeping side effects—logging, cache invalidation, notifications—cleanly decoupled from your model logic. Define listeners once and let the package wire them to the right events automatically.

  • Event-driven hooks for created, updated, deleted, and more
  • Annotation/config-based registration for zero-boilerplate listener binding
  • Decoupled architecture keeps models focused on business logic
  • PSR-friendly listener classes that are easy to test and reuse
  • Seamless integration with Hyperf's dependency injection container
Frequently asked questions about Model Listener
What is hyperf/model-listener used for?
hyperf/model-listener adds Eloquent-style model event listeners to Hyperf database models, so you can hook into lifecycle events such as created, updated, and deleted. It helps keep business logic decoupled by moving side effects into dedicated listener classes instead of scattering them across services or controllers. It is aimed at Hyperf applications, not Laravel.
How do I install hyperf/model-listener?
Install it with Composer using composer require hyperf/model-listener. Then follow the package documentation to register the listener configuration in your Hyperf application. Because this package is lightweight, setup is mostly about defining listener classes and mapping them to the model events you care about.
Does hyperf/model-listener work with Laravel?
No. hyperf/model-listener is built for Hyperf database models and does not replace Laravel's Eloquent observers or event dispatcher. Laravel developers will recognize the listener style, but in a Laravel application you should use native model events and observers. Use this package only when your application is running on Hyperf.
Which model events can I listen to with hyperf/model-listener?
It supports model lifecycle hooks such as created, updated, and deleted, along with other events exposed by Hyperf database models. The exact event list depends on the model implementation and the package's listener mapping. Check the README for the supported event names before wiring production logic.
How do I register a listener for a Hyperf model?
Define a listener class for the lifecycle event you want to handle, then associate that listener with the target model through the package's registration mechanism. Keep each listener focused on one responsibility so the decoupling benefit is real. The README is the authoritative source for exact class names, configuration keys, and registration syntax.
Is hyperf/model-listener a replacement for Laravel Eloquent observers?
It is not a drop-in replacement for Laravel Eloquent observers because it targets Hyperf, not Laravel. It borrows the Eloquent-style idea of model-bound lifecycle listeners, which can make migration to Hyperf feel familiar. If you need Laravel observer behavior inside Laravel, use Laravel's built-in features instead.
Can I use hyperf/model-listener in production?
Yes, provided you treat listeners as production code: keep them small, avoid slow synchronous work in hot model paths, and offload heavy tasks to queues. Pay attention to transaction boundaries and exception handling, because listener failures can affect the model operation that triggered them. Add monitoring and tests for critical side effects before deploying.
How do I test model listeners in Hyperf?
Trigger the relevant model lifecycle event in a Hyperf test case and assert the listener's observable side effects. Isolate database state with transactions or refreshes, and mock external services so tests stay deterministic. Cover both successful listener execution and failure paths.
Are there alternatives to hyperf/model-listener?
Alternatives include using Hyperf's event dispatcher directly, explicit service-layer calls, or other model observer patterns available in your stack. The package is most useful when you want Eloquent-style model-bound listeners without a heavier abstraction. Evaluate it against your existing Hyperf conventions and team familiarity.
Is hyperf/model-listener actively maintained?
The provided repository metadata does not include release history or maintainer activity, so check Packagist and the source repository before adopting it. Confirm compatibility with your Hyperf version and review recent commits or issue responses. For long-lived applications, pin the version and read changelogs before upgrades.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
vento/laravel-airbrake
wfeller/laravel-batch
maco-studios/mage-os-installer
busarm/armie
siberfx/laravel-logger
kfteam1991/dcat-admin
dashed/dashed-laposta
dashed/dashed-ecommerce-montaportal
dashed/dashed-ecommerce-etsy
neohq/string-blade-compiler
log1x/acf-composer
cgv/localized-resource
noith/settings
kda/laravel-package
kda/filament-dynamic-navigation
bypersoft/signbox
pairus/product-data
fayne/laravel-filament-cms-core
nodisrupt/laravel-agent
sierratecnologia/media-manager