trait HasRelationships (View source)
| protected array | $relations | The loaded relationships for the model. | |
| protected array | $touches | The relationships that should be touched on save. | |
| static string[] | $manyMethods | The many to many relationship methods. | |
| static protected array | $relationResolvers | The relation resolver callbacks. |
| mixed | relationResolver(string $class, string $key)
Get the dynamic relation resolver if defined or inherited, or return null. | |
| static void | resolveRelationUsing(string $name, Closure $callback)
Define a dynamic relation resolver. | |
| TRelatedModel,$this> | hasOne(TRelatedModel> $related, string|null $foreignKey = null, string|null $localKey = null)
Define a one-to-one relationship. | |
| TDeclaringModel> | newHasOne(Builder $query, Model $parent, string $foreignKey, string $localKey)
Instantiate a new HasOne relationship. | |
| hasOneThrough($related, $through, $firstKey = null, $secondKey = null, $localKey = null, $secondLocalKey = null) No description | ||
| newHasOneThrough(Builder $query, Model $farParent, Model $throughParent, $firstKey, $secondKey, $localKey, $secondLocalKey) No description | ||
| TRelatedModel,$this> | morphOne(TRelatedModel> $related, string $name, string|null $type = null, string|null $id = null, string|null $localKey = null)
Define a polymorphic one-to-one relationship. | |
| TDeclaringModel> | newMorphOne(Builder $query, Model $parent, string $type, string $id, string $localKey)
Instantiate a new MorphOne relationship. | |
| TRelatedModel,$this> | belongsTo(TRelatedModel> $related, string|null $foreignKey = null, string|null $ownerKey = null, string|null $relation = null)
Define an inverse one-to-one or many relationship. | |
| TDeclaringModel> | newBelongsTo(Builder $query, Model $child, string $foreignKey, string $ownerKey, string $relation)
Instantiate a new BelongsTo relationship. | |
| Model,$this> | morphTo(string|null $name = null, string|null $type = null, string|null $id = null, string|null $ownerKey = null)
Define a polymorphic, inverse one-to-one or many relationship. | |
| Model,$this> | morphEagerTo(string $name, string $type, string $id, string $ownerKey)
Define a polymorphic, inverse one-to-one or many relationship. | |
| Model,$this> | morphInstanceTo(string $target, string $name, string $type, string $id, string $ownerKey)
Define a polymorphic, inverse one-to-one or many relationship. | |
| TDeclaringModel> | newMorphTo(Builder $query, Model $parent, string $foreignKey, string $ownerKey, string $type, string $relation)
Instantiate a new MorphTo relationship. | |
| static string | getActualClassNameForMorph(string $class)
Retrieve the actual class name for a given morph class. | |
| string | guessBelongsToRelation()
Guess the "belongs to" relationship name. | |
| through($relationship)
Create a pending has-many-through or has-one-through relationship. | ||
| TRelatedModel,$this> | hasMany(TRelatedModel> $related, string|null $foreignKey = null, string|null $localKey = null)
Define a one-to-many relationship. | |
| TDeclaringModel> | newHasMany(Builder $query, Model $parent, string $foreignKey, string $localKey)
Instantiate a new HasMany relationship. | |
| hasManyThrough($related, $through, $firstKey = null, $secondKey = null, $localKey = null, $secondLocalKey = null) No description | ||
| newHasManyThrough(Builder $query, Model $farParent, Model $throughParent, $firstKey, $secondKey, $localKey, $secondLocalKey) No description | ||
| TRelatedModel,$this> | morphMany(TRelatedModel> $related, string $name, string|null $type = null, string|null $id = null, string|null $localKey = null)
Define a polymorphic one-to-many relationship. | |
| TDeclaringModel> | newMorphMany(Builder $query, Model $parent, string $type, string $id, string $localKey)
Instantiate a new MorphMany relationship. | |
| TRelatedModel,$this> | belongsToMany(TRelatedModel> $related, string|Model>|null $table = null, string|null $foreignPivotKey = null, string|null $relatedPivotKey = null, string|null $parentKey = null, string|null $relatedKey = null, string|null $relation = null)
Define a many-to-many relationship. | |
| TDeclaringModel> | newBelongsToMany(Builder $query, Model $parent, string|Model> $table, string $foreignPivotKey, string $relatedPivotKey, string $parentKey, string $relatedKey, string|null $relationName = null)
Instantiate a new BelongsToMany relationship. | |
| TRelatedModel,$this> | morphToMany(TRelatedModel> $related, string $name, string|null $table = null, string|null $foreignPivotKey = null, string|null $relatedPivotKey = null, string|null $parentKey = null, string|null $relatedKey = null, string|null $relation = null, bool $inverse = false)
Define a polymorphic many-to-many relationship. | |
| TDeclaringModel> | newMorphToMany(Builder $query, Model $parent, string $name, string $table, string $foreignPivotKey, string $relatedPivotKey, string $parentKey, string $relatedKey, string|null $relationName = null, bool $inverse = false)
Instantiate a new MorphToMany relationship. | |
| TRelatedModel,$this> | morphedByMany(TRelatedModel> $related, string $name, string|null $table = null, string|null $foreignPivotKey = null, string|null $relatedPivotKey = null, string|null $parentKey = null, string|null $relatedKey = null, string|null $relation = null)
Define a polymorphic, inverse many-to-many relationship. | |
| string|null | guessBelongsToManyRelation()
Get the relationship name of the belongsToMany relationship. | |
| string | joiningTable(string $related, Model|null $instance = null)
Get the joining table name for a many-to-many relation. | |
| string | joiningTableSegment()
Get this model's half of the intermediate table name for belongsToMany relationships. | |
| bool | touches(string $relation)
Determine if the model touches a given relation. | |
| void | touchOwners()
Touch the owning relations of the model. | |
| array | getMorphs(string $name, string $type, string $id)
Get the polymorphic relationship columns. | |
| string | getMorphClass()
Get the class name for polymorphic relations. | |
| mixed | newRelatedInstance(string $class)
Create a new model instance for a related model. | |
| mixed | newRelatedThroughInstance(string $class)
Create a new model instance for a related "through" model. | |
| array | getRelations()
Get all the loaded relations for the instance. | |
| mixed | getRelation(string $relation)
Get a specified relationship. | |
| bool | relationLoaded(string $key)
Determine if the given relation is loaded. | |
| $this | setRelation(string $relation, mixed $value)
Set the given relationship on the model. | |
| $this | unsetRelation(string $relation)
Unset a loaded relationship. | |
| $this | setRelations(array $relations)
Set the entire relations array on the model. | |
| $this | withoutRelations()
Duplicate the instance and unset all the loaded relations. | |
| $this | unsetRelations()
Unset all the loaded relations for the instance. | |
| array | getTouchedRelations()
Get the relationships that are touched on save. | |
| $this | setTouchedRelations(array $touches)
Set the relationships that are touched on save. |
Get the dynamic relation resolver if defined or inherited, or return null.
Define a dynamic relation resolver.
Define a one-to-one relationship.
Instantiate a new HasOne relationship.
No description
No description
Define a polymorphic one-to-one relationship.
Instantiate a new MorphOne relationship.
Define an inverse one-to-one or many relationship.
Instantiate a new BelongsTo relationship.
Define a polymorphic, inverse one-to-one or many relationship.
Define a polymorphic, inverse one-to-one or many relationship.
Define a polymorphic, inverse one-to-one or many relationship.
Instantiate a new MorphTo relationship.
Retrieve the actual class name for a given morph class.
Guess the "belongs to" relationship name.
Create a pending has-many-through or has-one-through relationship.
Define a one-to-many relationship.
Instantiate a new HasMany relationship.
No description
No description
Define a polymorphic one-to-many relationship.
Instantiate a new MorphMany relationship.
Define a many-to-many relationship.
Instantiate a new BelongsToMany relationship.
Define a polymorphic many-to-many relationship.
Instantiate a new MorphToMany relationship.
Define a polymorphic, inverse many-to-many relationship.
Get the relationship name of the belongsToMany relationship.
Get the joining table name for a many-to-many relation.
Get this model's half of the intermediate table name for belongsToMany relationships.
Determine if the model touches a given relation.
Touch the owning relations of the model.
Get the polymorphic relationship columns.
Get the class name for polymorphic relations.
Create a new model instance for a related model.
Create a new model instance for a related "through" model.
Get all the loaded relations for the instance.
Get a specified relationship.
Determine if the given relation is loaded.
Set the given relationship on the model.
Unset a loaded relationship.
Set the entire relations array on the model.
Duplicate the instance and unset all the loaded relations.
Unset all the loaded relations for the instance.
Get the relationships that are touched on save.
Set the relationships that are touched on save.
© Taylor Otwell
Licensed under the MIT License.
Laravel is a trademark of Taylor Otwell.
https://laravel.com/api/11.x/Illuminate/Database/Eloquent/Concerns/HasRelationships.html