Support the ongoing development of →
posted 10 years ago
Last updated 2 years ago.

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)"

Last updated 2 years ago.

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:

  • event name
  • what data is passed to hook
  • what data should be returned from hook.
Last updated 2 years ago.

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.

Last updated 2 years ago.

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.

Last updated 2 years ago.

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.

Last updated 2 years ago.

No it is possible:

$event = Event::fire('auth.login', array($user));

And you should check Illuminate/Events/Dispatcher@fire method

Last updated 2 years ago.

Sign in to participate in this thread!


Your banner here too?

revati revati Joined 31 Jan 2014


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

Your logo here?

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

© 2024 - All rights reserved.