Corcel\Model::belongsTo PHP Метод

belongsTo() публичный Метод

Replace the original belongsTo function to forward the connection name
public belongsTo ( string $related, null $foreignKey = null, null $otherKey = null, null $relation = null ) : BelongsTo
$related string
$foreignKey null
$otherKey null
$relation null
Результат Illuminate\Database\Eloquent\Relations\BelongsTo
    public function belongsTo($related, $foreignKey = null, $otherKey = null, $relation = null)
    {
        if (is_null($relation)) {
            list($current, $caller) = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
            $relation = $caller['function'];
        }
        if (is_null($foreignKey)) {
            $foreignKey = Str::snake($relation) . '_id';
        }
        $instance = new $related();
        if ($instance instanceof Model) {
            $instance->setConnection($this->getConnection()->getName());
        } else {
            $instance->setConnection($instance->getConnection()->getName());
        }
        $query = $instance->newQuery();
        $otherKey = $otherKey ?: $instance->getKeyName();
        return new BelongsTo($query, $this, $foreignKey, $otherKey, $relation);
    }