Infinite loop... because the Scope class depends on the authenticated user, which is scoped using this Scope class, which depends on the authenticated user, which is scoped using this Scope class.... and so on...
Oct 18, 2024
3
Level 63
ScopedBy not working ? => timeout
Hello,
I have added this code.
#[ObservedBy([UserObserver::class])]
#[ScopedBy([CompanyScope::class])]
class User extends Authenticatable implements MustVerifyEmail
{
...
}
With this scope.
class CompanyScope implements Scope
{
/**
* Apply the scope to a given Eloquent query builder.
*/
public function apply(Builder $builder, Model $model): void
{
$builder->where('company_id', auth()->user()->company_id);
}
}
Here is the query from the controller.
$users = User::
with('image', 'company')
->where(function ($query) {
$query
->where('role', '!=', RoleEnum::SUPERADMIN)
->orWhereNull('role');
})
->orderBy('name')
->get();
I get a timeout error.
What am I doing wrong ?
Thanks for your help.
V
Level 104
1 like
Please or to participate in this conversation.