You're browsing the documentation for an upcoming version of Laravel. The documentation and features of this release are subject to change.

MorphTo

Extends

Uses

Properties

protected

$morphType string

The type of the polymorphic relation.

Default: null
protected

$models Illuminate\...\Collection

The models whose relations are being eager loaded.

Default: null
protected

$dictionary array

All of the models keyed by ID.

Default: []
protected

$macroBuffer array

A buffer of dynamic calls to query macros.

Default: []
protected

$morphableEagerLoads array

A map of relations to load for each individual morph type.

Default: []
protected

$morphableEagerLoadCounts array

A map of relationship counts to load for each individual morph type.

Default: []
protected

$morphableConstraints array

A map of constraints to apply for each individual morph type.

Default: []

Methods

public

__construct ( Builder $query , Model $parent , $foreignKey , $ownerKey , $type , $relation ) : void

Create a new morph to relationship instance.

Parameters

  • $query Builder
  • $parent Model
  • $foreignKey string
  • $ownerKey string
  • $type string
  • $relation string
public

addEagerConstraints ( array $models ) : void

Set the constraints for an eager load of the relation.

Parameters

  • $models array
protected

buildDictionary ( Illuminate\...\Collection $models ) : void

Build a dictionary with the models.

Parameters

  • $models Illuminate\...\Collection
public

getEager ( ) : mixed

Get the results of the relationship.

protected

getResultsByType ( $type ) : Illuminate\...\Collection

Get all of the relation results for a type.

Parameters

  • $type string
protected

gatherKeysByType ( $type , $keyType ) : array

Gather all of the foreign keys for a given type.

Parameters

  • $type string
  • $keyType string
public

createModelByType ( $type ) : Model

Create a new model instance by type.

Parameters

  • $type string
public

match ( array $models , Illuminate\...\Collection $results , $relation ) : array

Match the eagerly loaded results to their parents.

Parameters

  • $models array
  • $results Illuminate\...\Collection
  • $relation string
protected

matchToMorphParents ( $type , Illuminate\...\Collection $results ) : void

Match the results for a given type to their parents.

Parameters

  • $type string
  • $results Illuminate\...\Collection
public

associate ( $model ) : Model

Associate the model instance to the given parent.

Parameters

public

dissociate ( ) : Model

Dissociate previously associated model from the given parent.

public

touch ( ) : void

Touch all of the related models for the relationship.

protected

newRelatedInstanceFor ( Model $parent ) : Model

Make a new related instance for the given model.

Parameters

public

getMorphType ( ) : string

Get the foreign key "type" name.

public

getDictionary ( ) : array

Get the dictionary used by the relationship.

public

morphWith ( array $with ) : MorphTo

Specify which relations to load for a given morph type.

Parameters

  • $with array
public

morphWithCount ( array $withCount ) : MorphTo

Specify which relationship counts to load for a given morph type.

Parameters

  • $withCount array
public

constrain ( array $callbacks ) : MorphTo

Specify constraints on the query for a given morph type.

Parameters

  • $callbacks array
protected

replayMacros ( Builder $query ) : Builder

Replay stored macro calls on the actual related instance.

Parameters

public

__call ( $method , $parameters ) : mixed

Handle dynamic method calls to the relationship.

Parameters

  • $method string
  • $parameters array