Is it possible to add a global scope after the model has already passed the constructor?
I would like to catch an event (for example creating
) and attach a global scope only if the model is creating.
So far I've done:
Event::listen('eloquent.creating*', function ($event, $model) {
/**
* @var Model $eloquentModel
*/
$eloquentModel = $model[0];
$eloquentModel->addGlobalScope(new AuthorizationScope($event));
});
The scope constructor is called, but the apply
method from it is never fired because the model at that point already obviously passed the part where it fires the scopes. How could I manually fire it?