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

Relation

Uses

Properties

protected

$query Builder

The Eloquent query builder instance.

Default: null
protected

$parent Model

The parent model instance.

Default: null
protected

The related model instance.

Default: null
protected static

$constraints bool

Indicates if the relation is adding constraints.

Default: true
public static

$morphMap array

An array to map class names to their morph names in the database.

Default: []
protected static

$requireMorphMap bool

Prevents morph relationships without a morph map.

Default: false
protected static

$selfJoinCount int

The count of self joins.

Methods

public

__construct ( Builder $query , Model $parent ) : void

Create a new relation instance.

Parameters

public static

noConstraints ( Closure $callback ) : mixed

Run a callback with constraints disabled on the relation.

Parameters

public abstract

addConstraints ( ) : void

Set the base constraints on the relation query.

public abstract

addEagerConstraints ( array $models ) : void

Set the constraints for an eager load of the relation.

Parameters

  • $models array
public abstract

initRelation ( array $models , $relation ) : array

Initialize the relation on a set of models.

Parameters

  • $models array
  • $relation string
public abstract

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

Match the eagerly loaded results to their parents.

Parameters

public abstract

getResults ( ) : mixed

Get the results of the relationship.

public

getEager ( ) : Collection

Get the relationship for eager loading.

public

sole ( $columns ) : Model

Execute the query and get the first result if it's the sole matching record.

Parameters

  • $columns array|string
public

get ( $columns ) : Collection

Execute the query as a "select" statement.

Parameters

  • $columns array
public

touch ( ) : void

Touch all of the related models for the relationship.

public

rawUpdate ( array $attributes ) : int

Run a raw update against the base query.

Parameters

  • $attributes array
public

getRelationExistenceCountQuery ( Builder $query , Builder $parentQuery ) : Builder

Add the constraints for a relationship count query.

Parameters

public

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

Add the constraints for an internal relationship existence query.

Parameters

public

getRelationCountHash ( $incrementJoinCount ) : string

Get a relationship join table hash.

Parameters

  • $incrementJoinCount bool
protected

getKeys ( array $models , $key ) : array

Get all of the primary keys for an array of models.

Parameters

  • $models array
  • $key string|null
protected

getRelationQuery ( ) : Builder

Get the query builder that will contain the relationship constraints.

public

getQuery ( ) : Builder

Get the underlying query for the relation.

public

getBaseQuery ( ) : Builder

Get the base query builder driving the Eloquent builder.

public

getParent ( ) : Model

Get the parent model of the relation.

public

getQualifiedParentKeyName ( ) : string

Get the fully qualified parent key name.

public

getRelated ( ) : Model

Get the related model of the relation.

public

createdAt ( ) : string

Get the name of the "created at" column.

public

updatedAt ( ) : string

Get the name of the "updated at" column.

public

relatedUpdatedAt ( ) : string

Get the name of the related model's "updated at" column.

protected

whereInMethod ( Model $model , $key ) : string

Get the name of the "where in" method for eager loading.

Parameters

public static

requireMorphMap ( $requireMorphMap ) : void

Prevent polymorphic relationships from being used without model mappings.

Parameters

  • $requireMorphMap bool
public static

requiresMorphMap ( ) : bool

Determine if polymorphic relationships require explicit model mapping.

public static

enforceMorphMap ( array $map , $merge ) : array

Define the morph map for polymorphic relations and require all morphed models to be explicitly mapped.

Parameters

  • $map array
  • $merge bool
public static

morphMap ( array $map , $merge ) : array

Set or get the morph map for polymorphic relations.

Parameters

  • $map array|null
  • $merge bool
protected static

buildMorphMapFromModels ( array $models ) : array|null

Builds a table-keyed array from model class names.

Parameters

  • $models string[]|null
public static

getMorphedModel ( $alias ) : string|null

Get the model associated with a custom polymorphic type.

Parameters

  • $alias string
public

__call ( $method , $parameters ) : mixed

Handle dynamic method calls to the relationship.

Parameters

  • $method string
  • $parameters array
public

__clone ( ) : void

Force a clone of the underlying query builder when cloning.