Support the ongoing development of Laravel.io →
posted 9 years ago
IOC

Is it possible to listen for different events with the same listener? Assuming the events were identical in every respect other than Class name, would it be possible to do something like:

handle(EventInterface $event) { ... }

in a listener?

So EventInterface would resolve to EventA or EventB.

Is this the right way of proceeding? Because now the problem becomes having to tell Laravel how to resolve the interface. I just want a scenario where the listener responds to either event A or event B. Is this possible or is there a better way?

Last updated 3 years ago.
0

Why are you not using Event subscriber approach for this?

0

Sign in to participate in this thread!

Eventy

Your banner here too?

andrewhl andrewhl Joined 12 Jun 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.