I just posted simillar post today and did not get any answer yet :)
I see it as perfect solutions in some cases, especially if you would like to decouple your components and stay in track with single responsibility principle etc.
But when working in a team it might make some confusion since as you said there are no support for IDE.
I am sorry but could you explain what you mean by saying "(what should be returned from event hook, what arguments are passed to event hook)"
This is view composer witch is triggered with events.
View::composer('profile', function($view)
{
$view->with('count', User::count());
});
In this case there is passed a view object as an argument, but it could be anything, and not just one. And in this case event does not expect anything to be returned from view composer, but in some cases there should be returned string, array, bool, object and so on.
So each time you are trying to hook to some event you need to know three things:
Well correct me if I am wrong but one of the main fundamentals of events is that, it should not return anything, since the event is one way action and dispacher does not know anything about the listeners/observers.
In this case of view composer I guess it listens an event with view identifier (group of actions that belongs to view event group) and I did not check the code but i guess it cannot accept string, array, bool etc but only obect instances of View.
Yes it would be right thing to do, but event can collect responses from all hooks (or till first response) as array.
From documentation: If false is returned from the creating, updating, saving, or deleting events, the action will be cancelled.
Well, yes you can return false in this case, however the return would go to the event manager to stop propagation but not event itself I guess.
No it is possible:
$event = Event::fire('auth.login', array($user));
And you should check Illuminate/Events/Dispatcher@fire method
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community