Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

DigitalMasters's avatar

Disable global scopes in nova

Hey guys, i am struggeling with disabling a global scope in nova. I have one resource with a hasOne relationship to another resource. I want to be able to create the relationship from the resource.

i disabled the global scope with the indexQuery function. Thats working fine and my entities that were hidden before are now showing up.

Additionally i tried to clear the booted models within the NovaServiceProvider.

public function boot()
    {
        parent::boot();

        Nova::serving(function() {
            Store::clearBootedModels();
        });
    }

Sadly that hat no effect.

The global scope will be used in the HasOne Relationship while finding the parentModel

 if ($this->ofManyRelationship === false && $request->viaRelationship === $this->attribute && $request->viaResourceId) {
                $parent = $parentResource::newModel()
                            ->with($this->attribute)
                            ->find($request->viaResourceId);

                return optional($parent->{$this->attribute})->exists === true;
            }

Here i always get null back because the global scope is still active.

Is there any other way to achieve my goal? Im stuck and have no clue...

Thanks in advance

0 likes
1 reply
LaryAI's avatar
Level 58

To disable a global scope in Laravel Nova, you can use the withoutGlobalScope method provided by Eloquent. Here's how you can modify your code to disable the global scope:

use App\Models\YourModel; // Replace with your actual model class

public function indexQuery(NovaRequest $request, $query)
{
    return $query->withoutGlobalScope('your_global_scope');
}

Replace 'your_global_scope' with the name of the global scope you want to disable. Make sure to replace YourModel with the actual model class that has the global scope.

If you want to disable the global scope for a specific relationship, you can use the withoutGlobalScopes method on the relationship query. Here's an example:

use App\Models\YourModel; // Replace with your actual model class

public function yourRelationship()
{
    return $this->hasOne(YourModel::class)->withoutGlobalScopes();
}

Again, replace YourModel with the actual model class.

Remember to clear the Laravel Nova cache by running the following command:

php artisan nova:publish

This should disable the global scope and allow you to create the relationship from the resource.

Please or to participate in this conversation.