Hello :) I think about using laravel events like this, because it seems for me a bit easier to read.
// Load event/listener
$dispatcher->listen('track.gtm.visit', TrackGTM::class);
// Later in code
event('track.gtm.visit');
I have a few questions about this:
Do you think this is a good idea, or should I go with the default solution to make it more readable for other developers? Because for me it feels, that this is more readable, because I have less files in my system.
Is there a way to put methods behind class like this:
$dispatcher->listen('track.gtm.visit', (new TrackGTM())->doIt());
Because this everytime triggers the doIt function and not only when I do the event() helper function with the event.
I've done a lot of Laravel projects in the past, and also taken over certain projects. Believe me, the best approach is keeping to the standards of Laravel. Any other developer will expect that because that's how it's documented.
Yes, you have some more code, but that doesn't mean that it's bad. Also, I think it's really nice to have an overview of all events and listeners in one service provider.
@bobbybouwmann Thx... I will do it with the standards of Laravel... Sometimes you have an idea and need somebody who says: "Do it like everyone else" :)