vendredi 24 novembre 2017

Laravel 5.5 - Gather multiple Eloquent events and than decide what to do

I have an event handler in EventServiceProvider boot method. To make it easier to understand I will explain case scenario:

  • user sign-in the system (web app of course)
  • he/she than populate form and hit the save button

Depending on what user picked on the form, multiple models/tables shall be updated. To me that means getting multiple eloquent.saving/creating etc. events fired. Example: user picked option A and Option B. Option A - model/tableA record created: I need to send email to IT Option B - model/tableA and tableB record created: I need to send email to IT and Marketing

In above case two emails would go to IT which is wrong. What I am trying to do is to accumulate all events of all models updated (dirty ones) and then pick certain one and execute associated action. That means once model/tableA gets updated I should capture that event and wait for all other events to get fired, store them in an array and pick certain on (I will know which one to pick) and execute email sending on any other action.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2jidKpm
via IFTTT

Aucun commentaire:

Enregistrer un commentaire