1

Lets say I have a User, Roles and User_Role table. I have a custom pivot model for my User_Role table. In a User model I have a relation like this

public function roles()
{
    return $this->belongsToMany(Role::class, 'User_Role')
        ->using(UserRole::class);
}

I have a global scope inside UserRole model which is not included in this relation. I could use wherePivot() and copy the scope but I was wondering is that necessary ? Is there a way for a BelongsToMany relation to respect global scopes defined inside Pivot model

Osta
  • 147
  • 5
  • 1
    I suppose the wherePivot() would be the best alternative here. Check this answer too: https://stackoverflow.com/questions/26073924/laravel-scope-by-pivot-data-values – Kevin Jul 06 '21 at 08:50

0 Answers0