MorphTo
class MorphTo extends BelongsTo mixin Builder
Traits
Properties
static protected array | $macros | The registered string macros. |
from Macroable |
protected Builder | $query | The Eloquent query builder instance. |
from Relation |
protected Model | $parent | The parent model instance. |
from Relation |
protected Model | $related | The related model instance. |
from Relation |
static protected bool | $constraints | Indicates if the relation is adding constraints. |
from Relation |
static protected array | $morphMap | An array to map class names to their morph names in database. |
from Relation |
protected Closure|array|bool | $withDefault | Indicates if a default model instance should be used. |
from SupportsDefaultModels |
protected | $child | The child model instance of the relation. |
from BelongsTo |
protected string | $foreignKey | The foreign key of the parent model. |
from BelongsTo |
protected string | $ownerKey | The associated key on the parent model. |
from BelongsTo |
protected string | $relation | The name of the relationship. |
from BelongsTo |
static protected int | $selfJoinCount | The count of self joins. |
from BelongsTo |
protected string | $morphType | The type of the polymorphic relation. |
|
protected Collection | $models | The models whose relations are being eager loaded. |
|
protected array | $dictionary | All of the models keyed by ID. |
|
protected array | $macroBuffer | A buffer of dynamic calls to query macros. |
Methods
Dynamically handle calls to the class.
Handle dynamic method calls to the relationship.
Create a new morph to relationship instance.
Set the constraints for an eager load of the relation.
Initialize the relation on a set of models.
Match the eagerly loaded results to their parents.
Get the results of the relationship.
Get the results of the relationship.
Add the constraints for a relationship count query.
Add the constraints for a relationship query.
Get all of the primary keys for an array of models.
Set or get the morph map for polymorphic relations.
Builds a table-keyed array from model class names.
Get the model associated with a custom polymorphic type.
Return a new model instance in case the relationship does not exist.
Gather the keys from an array of related models.
Dissociate previously associated model from the given parent.
Add the constraints for a relationship query on the same table.
Determine if the related model has an auto-incrementing ID.
Get the fully qualified foreign key of the relationship.
Get the fully qualified associated key of the relationship.
Get all of the relation results for a type.
Gather all of the foreign keys for a given type.
Create a new model instance by type.
Match the results for a given type to their parents.
Get the foreign key "type" name.
Get the dictionary used by the relationship.
Details
in
Macroable at line 24
static void
macro(string $name, callable $macro)
Register a custom macro.
in
Macroable at line 35
static bool
hasMacro(string $name)
Checks if macro is registered.
in
Macroable at line 49
static mixed
__callStatic(string $method, array $parameters)
Dynamically handle calls to the class.
at line 260
mixed
__call(string $method, array $parameters)
Handle dynamic method calls to the relationship.
at line 54
void
__construct(Builder $query, Model $parent, string $foreignKey, string $ownerKey, string $type, string $relation)
Create a new morph to relationship instance.
in
Relation at line 79
static mixed
noConstraints(Closure $callback)
Run a callback with constraints disabled on the relation.
in
BelongsTo at line 89
void
addConstraints()
Set the base constraints on the relation query.
at line 67
void
addEagerConstraints(array $models)
Set the constraints for an eager load of the relation.
in
BelongsTo at line 155
array
initRelation(array $models, string $relation)
Initialize the relation on a set of models.
at line 166
array
match(array $models, Collection $results, string $relation)
Match the eagerly loaded results to their parents.
at line 92
mixed
getResults()
Get the results of the relationship.
at line 104
Collection
getEager()
Get the results of the relationship.
Called via eager load method of Eloquent query builder.
in
Relation at line 151
void
touch()
Touch all of the related models for the relationship.
in
Relation at line 164
int
rawUpdate(array $attributes = [])
Run a raw update against the base query.
in
Relation at line 176
Builder
getRelationExistenceCountQuery(Builder $query, Builder $parentQuery)
Add the constraints for a relationship count query.
in
BelongsTo at line 249
Builder
getRelationExistenceQuery(Builder $query, Builder $parentQuery, array|mixed $columns = ['*'])
Add the constraints for a relationship query.
in
Relation at line 207
protected array
getKeys(array $models, string $key = null)
Get all of the primary keys for an array of models.
in
Relation at line 229
Builder
getBaseQuery()
Get the base query builder driving the Eloquent builder.
in
Relation at line 249
string
getQualifiedParentKeyName()
Get the fully qualified parent key name.
in
Relation at line 269
string
createdAt()
Get the name of the "created at" column.
in
Relation at line 279
string
updatedAt()
Get the name of the "updated at" column.
in
Relation at line 289
string
relatedUpdatedAt()
Get the name of the related model's "updated at" column.
in
Relation at line 301
static array
morphMap(array $map = null, bool $merge = true)
Set or get the morph map for polymorphic relations.
in
Relation at line 319
static protected array|null
buildMorphMapFromModels(array $models = null)
Builds a table-keyed array from model class names.
in
Relation at line 336
static string|null
getMorphedModel(string $alias)
Get the model associated with a custom polymorphic type.
in
Relation at line 370
void
__clone()
Force a clone of the underlying query builder when cloning.
in
SupportsDefaultModels at line 24
abstract protected Model
newRelatedInstanceFor(Model $parent)
Make a new related instance for the given model.
in
SupportsDefaultModels at line 32
$this
withDefault(Closure|array|bool $callback = true)
Return a new model instance in case the relationship does not exist.
in
SupportsDefaultModels at line 45
protected Model|null
getDefaultFor(Model $parent)
Get the default value for this relation.
in
BelongsTo at line 123
protected array
getEagerModelKeys(array $models)
Gather the keys from an array of related models.
in
BelongsTo at line 205
mixed
update(array $attributes)
Update the parent model on the relationship.
at line 195
Model
associate(Model|int|string $model)
Associate the model instance to the given parent.
at line 209
Model
dissociate()
Dissociate previously associated model from the given parent.
in
BelongsTo at line 268
Builder
getRelationExistenceQueryForSelfRelation(Builder $query, Builder $parentQuery, array|mixed $columns = ['*'])
Add the constraints for a relationship query on the same table.
in
BelongsTo at line 286
string
getRelationCountHash()
Get a relationship join table hash.
in
BelongsTo at line 296
protected bool
relationHasIncrementingId()
Determine if the related model has an auto-incrementing ID.
in
BelongsTo at line 318
string
getForeignKey()
Get the foreign key of the relationship.
in
BelongsTo at line 328
string
getQualifiedForeignKey()
Get the fully qualified foreign key of the relationship.
in
BelongsTo at line 338
string
getOwnerKey()
Get the associated key of the relationship.
in
BelongsTo at line 348
string
getQualifiedOwnerKeyName()
Get the fully qualified associated key of the relationship.
in
BelongsTo at line 358
string
getRelation()
Get the name of the relationship.
at line 78
protected void
buildDictionary(Collection $models)
Build a dictionary with the models.
at line 119
protected Collection
getResultsByType(string $type)
Get all of the relation results for a type.
at line 138
protected array
gatherKeysByType(string $type)
Gather all of the foreign keys for a given type.
at line 151
Model
createModelByType(string $type)
Create a new model instance by type.
at line 178
protected void
matchToMorphParents(string $type, Collection $results)
Match the results for a given type to their parents.
at line 223
string
getMorphType()
Get the foreign key "type" name.
at line 233
array
getDictionary()
Get the dictionary used by the relationship.