MorphTo
extends MorphTo
in package
Uses
DefinedConstraints
Table of Contents
- $morphMap : array<string|int, mixed>
- An array to map class names to their morph names in database.
- $child : mixed
- The child model instance of the relation.
- $constraints : bool
- Indicates if the relation is adding constraints.
- $dictionary : array<string|int, mixed>
- All of the models keyed by ID.
- $foreignKey : string
- The foreign key of the parent model.
- $macroBuffer : array<string|int, mixed>
- A buffer of dynamic calls to query macros.
- $macros : array<string|int, mixed>
- The registered string macros.
- $models : Collection
- The models whose relations are being eager loaded.
- $morphType : string
- The type of the polymorphic relation.
- $ownerKey : string
- The associated key on the parent model.
- $parent : Model
- The parent model instance.
- $query : Builder
- The Eloquent query builder instance.
- $related : Model
- The related model instance.
- $relation : string
- The name of the relationship.
- $relationName : string
- $selfJoinCount : int
- The count of self joins.
- $withDefault : Closure|array<string|int, mixed>|bool
- Indicates if a default model instance should be used.
- __call() : mixed
- Dynamically handle calls to the class.
- __callStatic() : mixed
- Dynamically handle calls to the class.
- __clone() : void
- Force a clone of the underlying query builder when cloning.
- __construct() : void
- Create a new morph to relationship instance.
- addConstraints() : void
- Set the base constraints on the relation query.
- addDefinedConstraints() : void
- Set the defined constraints on the relation query.
- addDefinedConstraintsToQuery() : mixed
- Add query based constraints.
- addDefinedConstraintsToRelation() : mixed
- Add relation based constraints.
- addEagerConstraints() : void
- Set the constraints for an eager load of the relation.
- associate() : Model
- Associate the model instance to the given parent.
- createdAt() : string
- Get the name of the "created at" column.
- createModelByType() : Model
- Create a new model instance by type.
- dissociate() : Model
- Dissociate previously associated model from the given parent.
- get() : Collection
- Execute the query as a "select" statement.
- getBaseQuery() : Builder
- Get the base query builder driving the Eloquent builder.
- getDictionary() : array<string|int, mixed>
- Get the dictionary used by the relationship.
- getEager() : Collection
- Get the relationship for eager loading.
- getForeignKey() : string
- Get the foreign key of the relationship.
- getMorphedModel() : string|null
- Get the model associated with a custom polymorphic type.
- getMorphType() : string
- Get the foreign key "type" name.
- getOwnerKey() : string
- Get the associated key of the relationship.
- getParent() : Model
- Get the parent model of the relation.
- getQualifiedForeignKey() : string
- Get the fully qualified foreign key of the relationship.
- getQualifiedOwnerKeyName() : string
- Get the fully qualified associated key of the relationship.
- getQualifiedParentKeyName() : string
- Get the fully qualified parent key name.
- getQuery() : Builder
- Get the underlying query for the relation.
- getRelated() : Model
- Get the related model of the relation.
- getRelation() : string
- Get the name of the relationship.
- getRelationCountHash() : string
- Get a relationship join table hash.
- getRelationExistenceCountQuery() : Builder
- Add the constraints for a relationship count query.
- getRelationExistenceQuery() : Builder
- Add the constraints for an internal relationship existence query.
- getRelationExistenceQueryForSelfRelation() : Builder
- Add the constraints for a relationship query on the same table.
- getResults() : mixed
- Get the results of the relationship.
- getSimpleValue() : mixed
- Helper for getting this relationship simple value, generally useful with form values.
- hasMacro() : bool
- Checks if macro is registered.
- initRelation() : array<string|int, mixed>
- Initialize the relation on a set of models.
- macro() : void
- Register a custom macro.
- match() : array<string|int, mixed>
- Match the eagerly loaded results to their parents.
- mixin() : void
- Mix another object into the class.
- morphMap() : array<string|int, mixed>
- Set or get the morph map for polymorphic relations.
- noConstraints() : mixed
- Run a callback with constraints disabled on the relation.
- rawUpdate() : int
- Run a raw update against the base query.
- relatedUpdatedAt() : string
- Get the name of the related model's "updated at" column.
- setSimpleValue() : mixed
- Helper for setting this relationship using various expected values. For example, $model->relation = $value;
- touch() : void
- Touch all of the related models for the relationship.
- update() : mixed
- Update the parent model on the relationship.
- updatedAt() : string
- Get the name of the "updated at" column.
- withDefault() : $this
- Return a new model instance in case the relationship does not exist.
- buildDictionary() : void
- Build a dictionary with the models.
- buildMorphMapFromModels() : array<string|int, mixed>|null
- Builds a table-keyed array from model class names.
- gatherKeysByType() : array<string|int, mixed>
- Gather all of the foreign keys for a given type.
- getDefaultFor() : Model|null
- Get the default value for this relation.
- getEagerModelKeys() : array<string|int, mixed>
- Gather the keys from an array of related models.
- getKeys() : array<string|int, mixed>
- Get all of the primary keys for an array of models.
- getResultsByType() : Collection
- Get all of the relation results for a type.
- matchToMorphParents() : void
- Match the results for a given type to their parents.
- newRelatedInstanceFor() : Model
- Make a new related instance for the given model.
- relationHasIncrementingId() : bool
- Determine if the related model has an auto-incrementing ID.
- replayMacros() : Builder
- Replay stored macro calls on the actual related instance.
Properties
$morphMap
An array to map class names to their morph names in database.
public
static array<string|int, mixed>
$morphMap
= []
$child
The child model instance of the relation.
protected
mixed
$child
$constraints
Indicates if the relation is adding constraints.
protected
static bool
$constraints
= true
$dictionary
All of the models keyed by ID.
protected
array<string|int, mixed>
$dictionary
= []
$foreignKey
The foreign key of the parent model.
protected
string
$foreignKey
$macroBuffer
A buffer of dynamic calls to query macros.
protected
array<string|int, mixed>
$macroBuffer
= []
$macros
The registered string macros.
protected
static array<string|int, mixed>
$macros
= []
$models
The models whose relations are being eager loaded.
protected
Collection
$models
$morphType
The type of the polymorphic relation.
protected
string
$morphType
$ownerKey
The associated key on the parent model.
protected
string
$ownerKey
$parent
The parent model instance.
protected
Model
$parent
$query
The Eloquent query builder instance.
protected
Builder
$query
$related
The related model instance.
protected
Model
$related
$relation
The name of the relationship.
protected
string
$relation
$relationName
protected
string
$relationName
The "name" of the relationship.
$selfJoinCount
The count of self joins.
protected
static int
$selfJoinCount
= 0
$withDefault
Indicates if a default model instance should be used.
protected
Closure|array<string|int, mixed>|bool
$withDefault
Alternatively, may be a Closure or array.
Methods
__call()
Dynamically handle calls to the class.
public
__call(string $method, array<string|int, mixed> $parameters) : mixed
Parameters
- $method : string
- $parameters : array<string|int, mixed>
Tags
Return values
mixed —__callStatic()
Dynamically handle calls to the class.
public
static __callStatic(string $method, array<string|int, mixed> $parameters) : mixed
Parameters
- $method : string
- $parameters : array<string|int, mixed>
Tags
Return values
mixed —__clone()
Force a clone of the underlying query builder when cloning.
public
__clone() : void
Return values
void —__construct()
Create a new morph to relationship instance.
public
__construct(Builder $query, Model $parent, mixed $foreignKey, mixed $otherKey, mixed $type, mixed $relationName) : void
Parameters
- $query : Builder
- $parent : Model
- $foreignKey : mixed
- $otherKey : mixed
- $type : mixed
- $relationName : mixed
Return values
void —addConstraints()
Set the base constraints on the relation query.
public
abstract addConstraints() : void
Return values
void —addDefinedConstraints()
Set the defined constraints on the relation query.
public
addDefinedConstraints() : void
Return values
void —addDefinedConstraintsToQuery()
Add query based constraints.
public
addDefinedConstraintsToQuery(QueryBuilder $query[, array<string|int, mixed> $args = null ]) : mixed
Parameters
- $query : QueryBuilder
- $args : array<string|int, mixed> = null
Return values
mixed —addDefinedConstraintsToRelation()
Add relation based constraints.
public
addDefinedConstraintsToRelation(Relation $relation[, array<string|int, mixed> $args = null ]) : mixed
Parameters
- $relation : Relation
- $args : array<string|int, mixed> = null
Return values
mixed —addEagerConstraints()
Set the constraints for an eager load of the relation.
public
abstract addEagerConstraints(array<string|int, mixed> $models) : void
Parameters
- $models : array<string|int, mixed>
Return values
void —associate()
Associate the model instance to the given parent.
public
associate(Model|int|string $model) : Model
Parameters
- $model : Model|int|string
Return values
Model —createdAt()
Get the name of the "created at" column.
public
createdAt() : string
Return values
string —createModelByType()
Create a new model instance by type.
public
createModelByType(string $type) : Model
Parameters
- $type : string
Return values
Model —dissociate()
Dissociate previously associated model from the given parent.
public
dissociate() : Model
Return values
Model —get()
Execute the query as a "select" statement.
public
get([array<string|int, mixed> $columns = ['*'] ]) : Collection
Parameters
- $columns : array<string|int, mixed> = ['*']
Return values
Collection —getBaseQuery()
Get the base query builder driving the Eloquent builder.
public
getBaseQuery() : Builder
Return values
Builder —getDictionary()
Get the dictionary used by the relationship.
public
getDictionary() : array<string|int, mixed>
Return values
array<string|int, mixed> —getEager()
Get the relationship for eager loading.
public
getEager() : Collection
Return values
Collection —getForeignKey()
Get the foreign key of the relationship.
public
getForeignKey() : string
Return values
string —getMorphedModel()
Get the model associated with a custom polymorphic type.
public
static getMorphedModel(string $alias) : string|null
Parameters
- $alias : string
Return values
string|null —getMorphType()
Get the foreign key "type" name.
public
getMorphType() : string
Return values
string —getOwnerKey()
Get the associated key of the relationship.
public
getOwnerKey() : string
Return values
string —getParent()
Get the parent model of the relation.
public
getParent() : Model
Return values
Model —getQualifiedForeignKey()
Get the fully qualified foreign key of the relationship.
public
getQualifiedForeignKey() : string
Return values
string —getQualifiedOwnerKeyName()
Get the fully qualified associated key of the relationship.
public
getQualifiedOwnerKeyName() : string
Return values
string —getQualifiedParentKeyName()
Get the fully qualified parent key name.
public
getQualifiedParentKeyName() : string
Return values
string —getQuery()
Get the underlying query for the relation.
public
getQuery() : Builder
Return values
Builder —getRelated()
Get the related model of the relation.
public
getRelated() : Model
Return values
Model —getRelation()
Get the name of the relationship.
public
getRelation() : string
Return values
string —getRelationCountHash()
Get a relationship join table hash.
public
getRelationCountHash() : string
Return values
string —getRelationExistenceCountQuery()
Add the constraints for a relationship count query.
public
getRelationExistenceCountQuery(Builder $query, Builder $parentQuery) : Builder
Parameters
Return values
Builder —getRelationExistenceQuery()
Add the constraints for an internal relationship existence query.
public
getRelationExistenceQuery(Builder $query, Builder $parentQuery[, array<string|int, mixed>|mixed $columns = ['*'] ]) : Builder
Essentially, these queries compare on column names like whereColumn.
Parameters
Return values
Builder —getRelationExistenceQueryForSelfRelation()
Add the constraints for a relationship query on the same table.
public
getRelationExistenceQueryForSelfRelation(Builder $query, Builder $parentQuery[, array<string|int, mixed>|mixed $columns = ['*'] ]) : Builder
Parameters
Return values
Builder —getResults()
Get the results of the relationship.
public
abstract getResults() : mixed
Return values
mixed —getSimpleValue()
Helper for getting this relationship simple value, generally useful with form values.
public
getSimpleValue() : mixed
Return values
mixed —hasMacro()
Checks if macro is registered.
public
static hasMacro(string $name) : bool
Parameters
- $name : string
Return values
bool —initRelation()
Initialize the relation on a set of models.
public
abstract initRelation(array<string|int, mixed> $models, string $relation) : array<string|int, mixed>
Parameters
- $models : array<string|int, mixed>
- $relation : string
Return values
array<string|int, mixed> —macro()
Register a custom macro.
public
static macro(string $name, object|callable $macro) : void
Parameters
- $name : string
- $macro : object|callable
Return values
void —match()
Match the eagerly loaded results to their parents.
public
abstract match(array<string|int, mixed> $models, Collection $results, string $relation) : array<string|int, mixed>
Parameters
- $models : array<string|int, mixed>
- $results : Collection
- $relation : string
Return values
array<string|int, mixed> —mixin()
Mix another object into the class.
public
static mixin(object $mixin) : void
Parameters
- $mixin : object
Return values
void —morphMap()
Set or get the morph map for polymorphic relations.
public
static morphMap([array<string|int, mixed>|null $map = null ][, bool $merge = true ]) : array<string|int, mixed>
Parameters
- $map : array<string|int, mixed>|null = null
- $merge : bool = true
Return values
array<string|int, mixed> —noConstraints()
Run a callback with constraints disabled on the relation.
public
static noConstraints(Closure $callback) : mixed
Parameters
- $callback : Closure
Return values
mixed —rawUpdate()
Run a raw update against the base query.
public
rawUpdate([array<string|int, mixed> $attributes = [] ]) : int
Parameters
- $attributes : array<string|int, mixed> = []
Return values
int —relatedUpdatedAt()
Get the name of the related model's "updated at" column.
public
relatedUpdatedAt() : string
Return values
string —setSimpleValue()
Helper for setting this relationship using various expected values. For example, $model->relation = $value;
public
setSimpleValue(mixed $value) : mixed
Parameters
- $value : mixed
Return values
mixed —touch()
Touch all of the related models for the relationship.
public
touch() : void
Return values
void —update()
Update the parent model on the relationship.
public
update(array<string|int, mixed> $attributes) : mixed
Parameters
- $attributes : array<string|int, mixed>
Return values
mixed —updatedAt()
Get the name of the "updated at" column.
public
updatedAt() : string
Return values
string —withDefault()
Return a new model instance in case the relationship does not exist.
public
withDefault([Closure|array<string|int, mixed>|bool $callback = true ]) : $this
Parameters
- $callback : Closure|array<string|int, mixed>|bool = true
Return values
$this —buildDictionary()
Build a dictionary with the models.
protected
buildDictionary(Collection $models) : void
Parameters
- $models : Collection
Return values
void —buildMorphMapFromModels()
Builds a table-keyed array from model class names.
protected
static buildMorphMapFromModels([array<string|int, string>|null $models = null ]) : array<string|int, mixed>|null
Parameters
- $models : array<string|int, string>|null = null
Return values
array<string|int, mixed>|null —gatherKeysByType()
Gather all of the foreign keys for a given type.
protected
gatherKeysByType(string $type) : array<string|int, mixed>
Parameters
- $type : string
Return values
array<string|int, mixed> —getDefaultFor()
Get the default value for this relation.
protected
getDefaultFor(Model $parent) : Model|null
Parameters
- $parent : Model
Return values
Model|null —getEagerModelKeys()
Gather the keys from an array of related models.
protected
getEagerModelKeys(array<string|int, mixed> $models) : array<string|int, mixed>
Parameters
- $models : array<string|int, mixed>
Return values
array<string|int, mixed> —getKeys()
Get all of the primary keys for an array of models.
protected
getKeys(array<string|int, mixed> $models[, string $key = null ]) : array<string|int, mixed>
Parameters
- $models : array<string|int, mixed>
- $key : string = null
Return values
array<string|int, mixed> —getResultsByType()
Get all of the relation results for a type.
protected
getResultsByType(string $type) : Collection
Parameters
- $type : string
Return values
Collection —matchToMorphParents()
Match the results for a given type to their parents.
protected
matchToMorphParents(string $type, Collection $results) : void
Parameters
- $type : string
- $results : Collection
Return values
void —newRelatedInstanceFor()
Make a new related instance for the given model.
protected
abstract newRelatedInstanceFor(Model $parent) : Model
Parameters
- $parent : Model
Return values
Model —relationHasIncrementingId()
Determine if the related model has an auto-incrementing ID.
protected
relationHasIncrementingId() : bool
Return values
bool —replayMacros()
Replay stored macro calls on the actual related instance.
protected
replayMacros(Builder $query) : Builder
Parameters
- $query : Builder