Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BelongsToMany relation withoutGlobalScope() is not being applied #51616

Closed
borovez opened this issue May 29, 2024 · 1 comment
Closed

BelongsToMany relation withoutGlobalScope() is not being applied #51616

borovez opened this issue May 29, 2024 · 1 comment

Comments

@borovez
Copy link

borovez commented May 29, 2024

Laravel Version

11.9.1

PHP Version

8.2

Database Driver & Version

No response

Description

I am unable to remove global scopes from my belongsToMany relationship.... I have tried it directly on the Location model which works, but if I attempt it on the relation, it doesn't get removed. Am I missing something? If I remove the global scope from the location model, it works as intended, but if I use withoutGlobalScope() on the relation definition, it doesn't remove the global scope.

Steps To Reproduce

// Location model
protected static function booted(): void
{
   parent::boot();
   static::addGlobalScope(new BelongsToLoggedInUserScope());
}
// User model
public function locations(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
{
    return $this->belongsToMany(Location::class, 'location_users', 'user_id', 'location_id')
        ->withoutGlobalScope(BelongsToLoggedInUserScope::class);
}
@borovez
Copy link
Author

borovez commented May 29, 2024

It was something unrelated...

@borovez borovez closed this as completed May 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant