Reputation: 18016
I have a scenario. We have integrated a third party application with our laravel app. At start we have a scenario that whenever client or project is created, updated and deleted, we need to send relevant data to third party application. For example if client is created on my web app, we need to also create on third party application and same is the case with update and delete. So I captured Laravel eloquent events in app service provider like
Client::created(function($client) use($integration) {
$integration->sendDataToIntegratedApps('client.create', $client);
});
Client::updated(function($client) use($integration) {
$integration->sendDataToIntegratedApps('client.update', $client);
});
Client::deleting(function($client) use($integration) {
$integration->sendDataToIntegratedApps('client.delete', $client);
});
It is working perfectly. But now we have an other requirement that whenever client is created/updated/deleted on third party app, we also need to do create/update/delete on our web app too.
Third party sends data through webhook, we receive data and when we try to do create/update/delete operations on web app, the above events also get triggered and data is again sent to third party application. For example a client is created on third party application, it will send data of created client to our web app. We create client on our web app. But when client is created, Client::created
event is fired and data is again sent to third party application that is wrong.
So now what I want,
If data created on our web app, the events should be fired. But if we are getting data from third party application first and then creating/updating/deleting the above events should not be fired. Is there any way to control such events or is there any other way to do this task?
Upvotes: 1
Views: 164
Reputation: 8282
If you're using Eloquent ORM for CRUD , from third party APP request too, it should fire the model event again.
either you have to use Query Builder for this CRUD (request from third party) then it should not fire the Model event. or you have to set some kind of flag for identifying the request comes from third party and should skip the Model event firing .
Hope it make sense..
Upvotes: 1