I made a scope which ends up somehow in an endless loop. While simplifying it to the minimal reproducible example I came to this:
public function apply(Builder $builder, Model $model)
{
Log::info('[Search] SQL: ' . $builder->toSql() . " Bindings: " . implode(', ', $builder->getBindings()));
}
The scope is implemented in the model in the standard way:
protected static function booted()
{
static::addGlobalScope(new AuthorizationScope());
}
If I run the code like this, I end up on the following error:
Maximum function nesting level of '256' reached, aborting!
Why is it impossible to get the SQL dump within the scope itself? Can this be amended somehow? Options like enabling the DB query log on other places are not really part of this question.