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

        return $query->where(
            $this->getKeyName(), $related->getAttribute($foreignKey)
        );
    }
public function scopeOwns(Builder $query, Model $related, ?string $foreignKey = null): Builder
    {
        if (\is_null($foreignKey)) {
            $foreignKey = $this->getForeignKey();
        }

        return $query->where(
            $this->getKeyName(), $related->getAttribute($foreignKey)
        );
    }
public function scopeOwns ( Builder $ query , Model $ related , ? string $ foreignKey = null ) : Builder { if ( \ is_null ( $ foreignKey ) ) { $ foreignKey = $ this -> getForeignKey ( ) ; } return $ query -> where ( $ this -> getKeyName ( ) , $ related -> getAttribute ( $ foreignKey ) ) ; }
Scope query to get model which related model actually owns the relationship.

@param  \Illuminate\Database\Eloquent\Builder  $query
@param  \Illuminate\Database\Eloquent\Model  $related
@param  string|null  $foreignKey

@return \Illuminate\Database\Eloquent\Builder
Scope query to get model which related model actually owns the relationship .