Suppose I have the models A
, B
, C
and D
. Now I want to listen for their created
event. Usually, I'd go to my AppServiceProvider
and add the events for each model, like this:
public function boot()
{
A::created(function ($a) {
//some code
});
B::created(function ($b) {
//some code
});
C::created(function ($c) {
//some code
});
D::created(function ($d) {
//some code
});
}
The code is the same, and I'd like to make that process faster since I actually have 70++ models. So is there a way to bind a single function to the created
event of all my models without having to do it one by one?
Edit: Turns out what I wanted was already in this question, but since it's already been answered I don't want to delete it.