Reputation: 4575
I have a nested model after every create or update I would like to send a post request with the model to an external API.
Should I do this in my model?
Upvotes: 0
Views: 88
Reputation: 239311
Should I do this in my model?
No, you shouldn't be doing this in your models. Instead, use an Observer. They're specifically meant for watching for events in your model layer, and triggering some code which shouldn't live in your model layer:
Observer classes respond to life cycle callbacks to implement trigger-like behavior outside the original class. This is a great way to reduce the clutter that normally comes when the model class is burdened with functionality that doesn’t pertain to the core responsibility of the class.
Upvotes: 3