Hi @makapaka I think you use withoutGlobalScope wrong. Try something like
public function removeGroupScope()
{
return $this->withoutGlobalScope('group');
}
then in your controller you can use it like
Model::removeGlobalScope()->get();
I have a global scope setup in model boot:
static::addGlobalScope('group', function (Builder $builder) {
$builder->where('group', '!=', 'true'); // NOT equal
});
In controller I have some logic to determine whether to cancel the scope or not, and so I call a function on the model:
public function removeGroupScope()
{
static::withoutGlobalScope('group');
}
It doesn't work as I expect: it still uses the group != true scope.
In the same function if I actually just add the global scope with different where clause it works - so I know the function runs, there must be a syntax error.
So this works, but don't think ideal:
public function removeGroupScope()
{
static::addGlobalScope('group', function (Builder $builder) {
$builder->where('group', '=', 'true'); // EQUAL
});
}
Any suggestions why specifically the withoutGlobalScope syntax doesn't work?
Please or to participate in this conversation.