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