Support the ongoing development of Laravel.io →
Architecture
Last updated 2 years ago.
0

Can't you simply rename the event to "login" with a handler of "loggedin" for example, and pass the user model into the "login" event which can then be accessed in the "loggedin" event handler as a property of the event "login"?

Just thinking out loud.

0

I guess I'm just not understanding how events are supposed to work - thanks for your suggestion but doesn't that put me back where I started - with a handler explicitly tied to one event?

What I want to achieve, and how it should all work in my mind is like this:

  • Fire 'some event'
  • Have a handler that listens for 'some event' and performs task A
  • At some point further down the line of development, I realise that I want to fire 'some other event'
  • The handler created above also listens for 'some other event' and performs task A

This way I have one handler that does a specific task being used by more than one event, hence keeping my handler DRY.

What am I missing!?

0

Did you ever find a solution to this ollie-new?

I have the same situation where I want to re-use a handler that creates an audit log...obviously it would be awesome and DRY to re-use this throughout the app under multiple events.

Cheers Dan

0

apparently you can assciate multiple things to one event in event service provider file?

protected $listen = [ 'mphm\Events\UserRegistered' => [ 'mphm\Listeners\EmailActivationLink', //first thing to happen '.....', //2nd thing etc ],

	'mphm\Events\UserForgotPassword' => [
		'mphm\Listeners\EmailPasswordForgottenLink',
	]

];
0

Sign in to participate in this thread!

Eventy

Your banner here too?

ollie-new ollie-new Joined 20 May 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.

© 2024 Laravel.io - All rights reserved.