public function scopeOwnedBy(Builder $query, Model $related, ?string $key = null): Builder
    {
        if (\is_null($key)) {
            $key = $related->getForeignKey();
        }

        return $query->where($key, $related->getKey());
    }