MorphOne
extends MorphOneOrMany
in package
Uses
SupportsDefaultModels
Table of Contents
- $morphMap : array<string|int, mixed>
- An array to map class names to their morph names in database.
- $constraints : bool
- Indicates if the relation is adding constraints.
- $foreignKey : string
- The foreign key of the parent model.
- $localKey : string
- The local key of the parent model.
- $macros : array<string|int, mixed>
- The registered string macros.
- $morphClass : string
- The class name of the parent model.
- $morphType : string
- The foreign key type for the relationship.
- $parent : Model
- The parent model instance.
- $query : Builder
- The Eloquent query builder instance.
- $related : Model
- The related model instance.
- $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 relation instance.
- addConstraints() : void
- Set the base constraints on the relation query.
- addEagerConstraints() : void
- Set the constraints for an eager load of the relation.
- create() : Model
- Create a new instance of the related model.
- createdAt() : string
- Get the name of the "created at" column.
- createMany() : Collection
- Create a Collection of new instances of the related model.
- findOrNew() : Collection|Model
- Find a model by its primary key or return new instance of the related model.
- firstOrCreate() : Model
- Get the first related record matching the attributes or create it.
- firstOrNew() : Model
- Get the first related model record matching the attributes or instantiate it.
- get() : Collection
- Execute the query as a "select" statement.
- getBaseQuery() : Builder
- Get the base query builder driving the Eloquent builder.
- getEager() : Collection
- Get the relationship for eager loading.
- getExistenceCompareKey() : string
- Get the key for comparing against the parent key in "has" query.
- getForeignKeyName() : string
- Get the plain foreign key.
- getMorphClass() : string
- Get the class name of the parent model.
- getMorphedModel() : string|null
- Get the model associated with a custom polymorphic type.
- getMorphType() : string
- Get the plain morph type name without the table.
- getParent() : Model
- Get the parent model of the relation.
- getParentKey() : mixed
- Get the key value of the parent's local key.
- getQualifiedForeignKeyName() : string
- Get the foreign key for the relationship.
- getQualifiedMorphType() : string
- Get the foreign key "type" name.
- 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.
- 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.
- 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.
- make() : Model
- Create and return an un-saved instance of the related model.
- match() : array<string|int, mixed>
- Match the eagerly loaded results to their parents.
- matchMany() : array<string|int, mixed>
- Match the eagerly loaded results to their many parents.
- matchOne() : array<string|int, mixed>
- Match the eagerly loaded results to their single parents.
- mixin() : void
- Mix another object into the class.
- morphMap() : array<string|int, mixed>
- Set or get the morph map for polymorphic relations.
- newRelatedInstanceFor() : Model
- Make a new related instance for the given model.
- 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.
- save() : Model|false
- Attach a model instance to the parent model.
- saveMany() : Traversable|array<string|int, mixed>
- Attach a collection of models to the parent instance.
- touch() : void
- Touch all of the related models for the relationship.
- update() : int
- Perform an update on all the related models.
- updatedAt() : string
- Get the name of the "updated at" column.
- updateOrCreate() : Model
- Create or update a related record matching the attributes, and fill it with values.
- withDefault() : $this
- Return a new model instance in case the relationship does not exist.
- buildDictionary() : array<string|int, mixed>
- Build model dictionary keyed by the relation's foreign key.
- buildMorphMapFromModels() : array<string|int, mixed>|null
- Builds a table-keyed array from model class names.
- getDefaultFor() : Model|null
- Get the default value for this relation.
- getKeys() : array<string|int, mixed>
- Get all of the primary keys for an array of models.
- getRelationValue() : mixed
- Get the value of a relationship by one or many type.
- matchOneOrMany() : array<string|int, mixed>
- Match the eagerly loaded results to their many parents.
- setForeignAttributesForCreate() : void
- Set the foreign ID for creating a related model.
Properties
$morphMap
An array to map class names to their morph names in database.
public
static array<string|int, mixed>
$morphMap
= []
$constraints
Indicates if the relation is adding constraints.
protected
static bool
$constraints
= true
$foreignKey
The foreign key of the parent model.
protected
string
$foreignKey
$localKey
The local key of the parent model.
protected
string
$localKey
$macros
The registered string macros.
protected
static array<string|int, mixed>
$macros
= []
$morphClass
The class name of the parent model.
protected
string
$morphClass
$morphType
The foreign key type for the relationship.
protected
string
$morphType
$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
$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 relation instance.
public
__construct(Builder $query, Model $parent) : void
Parameters
Return values
void —addConstraints()
Set the base constraints on the relation query.
public
abstract addConstraints() : void
Return values
void —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 —create()
Create a new instance of the related model.
public
create([array<string|int, mixed> $attributes = [] ]) : Model
Parameters
- $attributes : array<string|int, mixed> = []
Return values
Model —createdAt()
Get the name of the "created at" column.
public
createdAt() : string
Return values
string —createMany()
Create a Collection of new instances of the related model.
public
createMany(array<string|int, mixed> $records) : Collection
Parameters
- $records : array<string|int, mixed>
Return values
Collection —findOrNew()
Find a model by its primary key or return new instance of the related model.
public
findOrNew(mixed $id[, array<string|int, mixed> $columns = ['*'] ]) : Collection|Model
Parameters
- $id : mixed
- $columns : array<string|int, mixed> = ['*']
Return values
Collection|Model —firstOrCreate()
Get the first related record matching the attributes or create it.
public
firstOrCreate(array<string|int, mixed> $attributes[, array<string|int, mixed> $values = [] ]) : Model
Parameters
- $attributes : array<string|int, mixed>
- $values : array<string|int, mixed> = []
Return values
Model —firstOrNew()
Get the first related model record matching the attributes or instantiate it.
public
firstOrNew(array<string|int, mixed> $attributes[, array<string|int, mixed> $values = [] ]) : Model
Parameters
- $attributes : array<string|int, mixed>
- $values : array<string|int, mixed> = []
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 —getEager()
Get the relationship for eager loading.
public
getEager() : Collection
Return values
Collection —getExistenceCompareKey()
Get the key for comparing against the parent key in "has" query.
public
getExistenceCompareKey() : string
Return values
string —getForeignKeyName()
Get the plain foreign key.
public
getForeignKeyName() : string
Return values
string —getMorphClass()
Get the class name of the parent model.
public
getMorphClass() : 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 plain morph type name without the table.
public
getMorphType() : string
Return values
string —getParent()
Get the parent model of the relation.
public
getParent() : Model
Return values
Model —getParentKey()
Get the key value of the parent's local key.
public
getParentKey() : mixed
Return values
mixed —getQualifiedForeignKeyName()
Get the foreign key for the relationship.
public
getQualifiedForeignKeyName() : string
Return values
string —getQualifiedMorphType()
Get the foreign key "type" name.
public
getQualifiedMorphType() : 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 —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
getResults() : 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
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 —make()
Create and return an un-saved instance of the related model.
public
make([array<string|int, mixed> $attributes = [] ]) : Model
Parameters
- $attributes : array<string|int, mixed> = []
Return values
Model —match()
Match the eagerly loaded results to their parents.
public
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> —matchMany()
Match the eagerly loaded results to their many parents.
public
matchMany(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> —matchOne()
Match the eagerly loaded results to their single parents.
public
matchOne(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> —newRelatedInstanceFor()
Make a new related instance for the given model.
public
newRelatedInstanceFor(Model $parent) : Model
Parameters
- $parent : Model
Return values
Model —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 —save()
Attach a model instance to the parent model.
public
save(Model $model) : Model|false
Parameters
- $model : Model
Return values
Model|false —saveMany()
Attach a collection of models to the parent instance.
public
saveMany(Traversable|array<string|int, mixed> $models) : Traversable|array<string|int, mixed>
Parameters
- $models : Traversable|array<string|int, mixed>
Return values
Traversable|array<string|int, mixed> —touch()
Touch all of the related models for the relationship.
public
touch() : void
Return values
void —update()
Perform an update on all the related models.
public
update(array<string|int, mixed> $attributes) : int
Parameters
- $attributes : array<string|int, mixed>
Return values
int —updatedAt()
Get the name of the "updated at" column.
public
updatedAt() : string
Return values
string —updateOrCreate()
Create or update a related record matching the attributes, and fill it with values.
public
updateOrCreate(array<string|int, mixed> $attributes[, array<string|int, mixed> $values = [] ]) : Model
Parameters
- $attributes : array<string|int, mixed>
- $values : array<string|int, mixed> = []
Return values
Model —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 model dictionary keyed by the relation's foreign key.
protected
buildDictionary(Collection $results) : array<string|int, mixed>
Parameters
- $results : Collection
Return values
array<string|int, mixed> —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 —getDefaultFor()
Get the default value for this relation.
protected
getDefaultFor(Model $parent) : Model|null
Parameters
- $parent : Model
Return values
Model|null —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> —getRelationValue()
Get the value of a relationship by one or many type.
protected
getRelationValue(array<string|int, mixed> $dictionary, string $key, string $type) : mixed
Parameters
- $dictionary : array<string|int, mixed>
- $key : string
- $type : string
Return values
mixed —matchOneOrMany()
Match the eagerly loaded results to their many parents.
protected
matchOneOrMany(array<string|int, mixed> $models, Collection $results, string $relation, string $type) : array<string|int, mixed>
Parameters
- $models : array<string|int, mixed>
- $results : Collection
- $relation : string
- $type : string
Return values
array<string|int, mixed> —setForeignAttributesForCreate()
Set the foreign ID for creating a related model.
protected
setForeignAttributesForCreate(Model $model) : void
Parameters
- $model : Model