app/Database/Eloquent/Concerns/HasRelationships.php
public function belongsToOne($related, $table = null, $foreignPivotKey = null, $relatedPivotKey = null,
                                  $parentKey = null, $relatedKey = null, $relation = null)
    {
        // If no relationship name was passed, we will pull backtraces to get the
        // name of the calling function. We will use that function name as the
        // title of this relation since that is a great convention to apply.
        if (is_null($relation)) {
            $relation = $this->guessBelongsToOneRelation();
        }

        // First, we'll need to determine the foreign key and "other key" for the
        // relationship. Once we have determined the keys we'll make the query
        // instances as well as the relationship instances we need for this.
        $instance = $this->newRelatedInstance($related);

        $foreignPivotKey = $foreignPivotKey ?: $this->getForeignKey();

        $relatedPivotKey = $relatedPivotKey ?: $instance->getForeignKey();

        // If no table name was provided, we can guess it by concatenating the two
        // models using underscores in alphabetical order. The two model names
        // are transformed to snake case from their default CamelCase also.
        if (is_null($table)) {
            $table = $this->joiningTable($related);
        }

        return $this->newBelongsToOne(
            $instance->newQuery(), $this, $table, $foreignPivotKey,
            $relatedPivotKey, $parentKey ?: $this->getKeyName(),
            $relatedKey ?: $instance->getKeyName(), $relation
        );
    }
public function belongsToOne($related, $table = null, $foreignPivotKey = null, $relatedPivotKey = null,
                                  $parentKey = null, $relatedKey = null, $relation = null)
    {
        // If no relationship name was passed, we will pull backtraces to get the
        // name of the calling function. We will use that function name as the
        // title of this relation since that is a great convention to apply.
        if (is_null($relation)) {
            $relation = $this->guessBelongsToOneRelation();
        }

        // First, we'll need to determine the foreign key and "other key" for the
        // relationship. Once we have determined the keys we'll make the query
        // instances as well as the relationship instances we need for this.
        $instance = $this->newRelatedInstance($related);

        $foreignPivotKey = $foreignPivotKey ?: $this->getForeignKey();

        $relatedPivotKey = $relatedPivotKey ?: $instance->getForeignKey();

        // If no table name was provided, we can guess it by concatenating the two
        // models using underscores in alphabetical order. The two model names
        // are transformed to snake case from their default CamelCase also.
        if (is_null($table)) {
            $table = $this->joiningTable($related);
        }

        return $this->newBelongsToOne(
            $instance->newQuery(), $this, $table, $foreignPivotKey,
            $relatedPivotKey, $parentKey ?: $this->getKeyName(),
            $relatedKey ?: $instance->getKeyName(), $relation
        );
    }
public function belongsToOne ( $ related , $ table = null , $ foreignPivotKey = null , $ relatedPivotKey = null , $ parentKey = null , $ relatedKey = null , $ relation = null ) { // If no relationship name was passed, we will pull backtraces to get the // name of the calling function. We will use that function name as the // title of this relation since that is a great convention to apply. if ( is_null ( $ relation ) ) { $ relation = $ this -> guessBelongsToOneRelation ( ) ; } // First, we'll need to determine the foreign key and "other key" for the // relationship. Once we have determined the keys we'll make the query // instances as well as the relationship instances we need for this. $ instance = $ this -> newRelatedInstance ( $ related ) ; $ foreignPivotKey = $ foreignPivotKey ? : $ this -> getForeignKey ( ) ; $ relatedPivotKey = $ relatedPivotKey ? : $ instance -> getForeignKey ( ) ; // If no table name was provided, we can guess it by concatenating the two // models using underscores in alphabetical order. The two model names // are transformed to snake case from their default CamelCase also. if ( is_null ( $ table ) ) { $ table = $ this -> joiningTable ( $ related ) ; } return $ this -> newBelongsToOne ( $ instance -> newQuery ( ) , $ this , $ table , $ foreignPivotKey , $ relatedPivotKey , $ parentKey ? : $ this -> getKeyName ( ) , $ relatedKey ? : $ instance -> getKeyName ( ) , $ relation ) ; }
Define a one-to-one via pivot relationship.

@param  string  $related
@param  string  $table
@param  string  $foreignPivotKey
@param  string  $relatedPivotKey
@param  string  $parentKey
@param  string  $relatedKey
@param  string  $relation
@return \Atnic\LaravelGenerator\Database\Eloquent\Relations\BelongsToOne
Define a one - to - one via pivot relationship .