class X extends Model
{
protected static function booted()
{
static::retrieved(function ($model) {
// This event will not be triggered when accessing the relationship method
if (!app()->runningInConsole() && !app()->runningUnitTests()) {
// Event Logic
}
});
}
public function children()
{
// Disable events for this query
return $this->hasMany(Child::class)->withoutEvents();
}
}