You are viewing an older version of the documentation. For the latest, please visit master documentation.

BelongsTo

Extends

Uses

Properties

protected

$child Model

The child model instance of the relation.

Default: null
protected

$foreignKey string

The foreign key of the parent model.

Default: null
protected

$ownerKey string

The associated key on the parent model.

Default: null
protected

$relationName string

The name of the relationship.

Default: null

Methods

public

__construct ( Builder $query , Model $child , $foreignKey , $ownerKey , $relationName ) : void

Create a new belongs to relationship instance.

Parameters

  • $query Builder
  • $child Model
  • $foreignKey string
  • $ownerKey string
  • $relationName string
public

getResults ( ) : mixed

Get the results of the relationship.

public

addConstraints ( ) : void

Set the base constraints on the relation query.

public

addEagerConstraints ( array $models ) : void

Set the constraints for an eager load of the relation.

Parameters

  • $models array
protected

getEagerModelKeys ( array $models ) : array

Gather the keys from an array of related models.

Parameters

  • $models array
public

initRelation ( array $models , $relation ) : array

Initialize the relation on a set of models.

Parameters

  • $models array
  • $relation string
public

match ( array $models , Collection $results , $relation ) : array

Match the eagerly loaded results to their parents.

Parameters

public

associate ( $model ) : Model

Associate the model instance to the given parent.

Parameters

  • $model Model |int|string|null
public

dissociate ( ) : Model

Dissociate previously associated model from the given parent.

public

disassociate ( ) : Model

Alias of "dissociate" method.

public

getRelationExistenceQuery ( Builder $query , Builder $parentQuery , $columns ) : Builder

Add the constraints for a relationship query.

Parameters

public

getRelationExistenceQueryForSelfRelation ( Builder $query , Builder $parentQuery , $columns ) : Builder

Add the constraints for a relationship query on the same table.

Parameters

protected

relationHasIncrementingId ( ) : bool

Determine if the related model has an auto-incrementing ID.

protected

newRelatedInstanceFor ( Model $parent ) : Model

Make a new related instance for the given model.

Parameters

public

getChild ( ) : Model

Get the child of the relationship.

public

getForeignKeyName ( ) : string

Get the foreign key of the relationship.

public

getQualifiedForeignKeyName ( ) : string

Get the fully qualified foreign key of the relationship.

public

getParentKey ( ) : mixed

Get the key value of the child's foreign key.

public

getOwnerKeyName ( ) : string

Get the associated key of the relationship.

public

getQualifiedOwnerKeyName ( ) : string

Get the fully qualified associated key of the relationship.

protected

getRelatedKeyFrom ( Model $model ) : mixed

Get the value of the model's associated key.

Parameters

public

getRelationName ( ) : string

Get the name of the relationship.