Idea of Event in the Laravel

Asked

Viewed 139 times

0

I’m developing a system in Laravel(php). I read in several articles that "we should" use "EVENTS" to perform actions after the main one has been done, for example:
-> in the controller:
// I register a user
// calls Event(store)

-> in the Event store, there is a system for each item, ex:
//register in the specified user group.
//e-mail us about the registration.
// ...

The idea is really this?

'Cause I thought it could be done this way too:
-> in the controller
// calls Event store

-> in the Event store:
//makes the user registration
//register in the specified user group.
//e-mail us about the registration. // ..

1 answer

0

Events should be used to perform functions when an action occurs in the system, the controller will be responsible for, for example, saving the model, so it triggers an event that can be called NovoModeloCriado, this way several listeners of the event can perform the actions, such as sending an email, doing statistical calculations at the base, creating a new record in another table related to the context of the saved model.

See the answer in /a/207423/819 for more details on Events and eloquenbt Observers.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.