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)
I get all the records.
App\MyModel::withoutGlobalScopes()->get();
Defining the full class path solves the problem:
App\MyModel::withoutGlobalScope('App\Scopes\ArchiveScope')->get();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With