I want to run a similar task on some different eloquent events in laravel.
For example Suppose I have a Question
model. For my purpose, I used boot()
function on the model like this :
class Question extends Model
public static function boot ()
{
parent::boot();
static::updated(function ($Question) {
//some Tasks on $Question
});
static::updating(function ($Question) {
//some Tasks on $Question
});
static::created(function ($Question) {
//some Tasks on $Question
});
static::creating(function ($Question) {
//some Tasks on $Question
});
}
}
As you see in all events , similar Tasks run and may have large code.
what is best and short approach to do that?