public function scopeWhereSubjectVisibleTo(Builder $query, User $actor)
    {
        $query->where(function ($query) use ($actor) {
            $classes = [];

            foreach (static::$subjectModels as $type => $class) {
                $classes[$class][] = $type;
            }

            foreach ($classes as $class => $types) {
                $query->orWhere(function ($query) use ($types, $class, $actor) {
                    $query->whereIn('type', $types)
                        ->whereExists(function ($query) use ($class, $actor) {
                            $query->selectRaw(1)
                                ->from((new $class)->getTable())
                                ->whereColumn('id', 'subject_id');

                            static::$dispatcher->dispatch(
                                new ScopeModelVisibility($class::query()->setQuery($query), $actor, 'view')
                            );
                        });
                });
            }
        });
    }