'Laravel without anonymous global scope on relation

I'm using code from another developer with a global scope model, Course.

protected static function booted()
{
    static::addGlobalScope('filter', function (Builder $builder) {
        $builder->whereHas('teachers', function ($q) {
            $q->where('course_user.user_id', '=', auth()->user()->id);
        });
    });
}

And for the User:

public function canTeach()
{
    return $this->belongsToMany(
        Course::class,
        'sessions_teacher_access',
        'user_id',
        'course_id')->withoutGlobalScope('filter');
}

How can I get the relationship without the global scope?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source