Laravel 12.29: Disable all global scopes except chosen
laravel
release
eloquent
Nabil Hassen
•
Sep 18, 2025
Last updated on Sep 18, 2025
Table of contents:
New in Laravel 12.29: withoutGlobalScopesExcept()
Laravel 12.29 introduces a handy new Eloquent method: withoutGlobalScopesExcept(). This lets you disable all global scopes on a query except the ones you explicitly want to keep.
What it does
Previously, you could:
- Use
withoutGlobalScope()to remove one scope. - Use
withoutGlobalScopes()to remove all or several scopes.
Now, with:
Post::withoutGlobalScopesExcept(['tenant'])->get();
You remove all global scopes except tenant.
Example
class Post extends Model{ protected static function booted() { static::addGlobalScope('published', fn ($q) => $q->where('published', true)); static::addGlobalScope('tenant', fn ($q) => $q->where('tenant_id', auth()->id())); }} // Only keep the tenant scope:$posts = Post::withoutGlobalScopesExcept(['tenant'])->get();
Why it matters
This feature makes queries more expressive and concise. Instead of manually disabling multiple scopes or re‑adding conditions, you can whitelist just the ones you need.
For details, see PR #56957.
Stay Updated.
I'll you email you as soon as new, fresh content is published.
Thanks for subscribing to my blog.