Mmh that should actually work! Are you sure the namespace of the scope is correct? Is it imported the correct way?
Also how do you register your global scope? There are multiple ways for that as well!
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I have a global query scope called ArchiveScope that mimics the similar functionality of Soft Deletion. The apply method of that scope looks like this:
public function apply(Builder $builder, Model $model)
{
$builder->where('archived_at', '=', NULL);
}
So when I use MyModel::all(), it returns all the rows that do not have a timestamp (i.e. NULL). But when I want to fetch all the records (including archived), I still get the same result. I am running this statement in the tinker:
App\MyModel::withoutGlobalScope(ArchiveScope::class)->get();
Strangely, when I use withoutGlobalScopes() instead of withoutGlobalScope(ArchiveScope::class) then I get all the records.
App\MyModel::withoutGlobalScopes()->get();
Turns out when I use the full class path, then it works:
App\MyModel::withoutGlobalScope('App\Scopes\ArchiveScope')->get();
Previously I have been using this:
App\MyModel::withoutGlobalScope(ArchiveScope::class)->get();
...as the documentation suggested.
I am using PHP 7.2.5.
Please or to participate in this conversation.