Support the ongoing development of Laravel.io →
posted 9 years ago
Architecture
Last updated 1 year ago.
0

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 1 year ago.
0

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 1 year ago.
0

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 1 year ago.
0

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 1 year ago.
0

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 1 year ago.
0

No it is possible:

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

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

Last updated 1 year ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

revati revati Joined 31 Jan 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.