Documentation

HasRelationships

Table of Contents

$manyMethods  : array<string|int, mixed>
The many to many relationship methods.
$relations  : array<string|int, mixed>
The loaded relationships for the model.
$touches  : array<string|int, mixed>
The relationships that should be touched on save.
belongsTo()  : BelongsTo
Define an inverse one-to-one or many relationship.
belongsToMany()  : BelongsToMany
Define a many-to-many relationship.
getActualClassNameForMorph()  : string
Retrieve the actual class name for a given morph class.
getMorphClass()  : string
Get the class name for polymorphic relations.
getRelation()  : mixed
Get a specified relationship.
getRelations()  : array<string|int, mixed>
Get all the loaded relations for the instance.
getTouchedRelations()  : array<string|int, mixed>
Get the relationships that are touched on save.
hasMany()  : HasMany
Define a one-to-many relationship.
hasManyThrough()  : HasManyThrough
Define a has-many-through relationship.
hasOne()  : HasOne
Define a one-to-one relationship.
joiningTable()  : string
Get the joining table name for a many-to-many relation.
morphedByMany()  : MorphToMany
Define a polymorphic, inverse many-to-many relationship.
morphMany()  : MorphMany
Define a polymorphic one-to-many relationship.
morphOne()  : MorphOne
Define a polymorphic one-to-one relationship.
morphTo()  : MorphTo
Define a polymorphic, inverse one-to-one or many relationship.
morphToMany()  : MorphToMany
Define a polymorphic many-to-many relationship.
relationLoaded()  : bool
Determine if the given relation is loaded.
setRelation()  : $this
Set the specific relationship in the model.
setRelations()  : $this
Set the entire relations array on the model.
setTouchedRelations()  : $this
Set the relationships that are touched on save.
touches()  : bool
Determine if the model touches a given relation.
touchOwners()  : void
Touch the owning relations of the model.
getMorphs()  : array<string|int, mixed>
Get the polymorphic relationship columns.
guessBelongsToManyRelation()  : string
Get the relationship name of the belongs to many.
guessBelongsToRelation()  : string
Guess the "belongs to" relationship name.
morphEagerTo()  : MorphTo
Define a polymorphic, inverse one-to-one or many relationship.
morphInstanceTo()  : MorphTo
Define a polymorphic, inverse one-to-one or many relationship.
newBelongsTo()  : BelongsTo
Instantiate a new BelongsTo relationship.
newBelongsToMany()  : BelongsToMany
Instantiate a new BelongsToMany relationship.
newHasMany()  : HasMany
Instantiate a new HasMany relationship.
newHasManyThrough()  : HasManyThrough
Instantiate a new HasManyThrough relationship.
newHasOne()  : HasOne
Instantiate a new HasOne relationship.
newMorphMany()  : MorphMany
Instantiate a new MorphMany relationship.
newMorphOne()  : MorphOne
Instantiate a new MorphOne relationship.
newMorphTo()  : MorphTo
Instantiate a new MorphTo relationship.
newMorphToMany()  : MorphToMany
Instantiate a new HasManyThrough relationship.
newRelatedInstance()  : mixed
Create a new model instance for a related model.

Properties

$manyMethods

The many to many relationship methods.

public static array<string|int, mixed> $manyMethods = ['belongsToMany', 'morphToMany', 'morphedByMany', 'guessBelongsToManyRelation', 'findFirstMethodThatIsntRelation']

$relations

The loaded relationships for the model.

protected array<string|int, mixed> $relations = []

$touches

The relationships that should be touched on save.

protected array<string|int, mixed> $touches = []

Methods

belongsTo()

Define an inverse one-to-one or many relationship.

public belongsTo(string $related[, string $foreignKey = null ][, string $ownerKey = null ][, string $relation = null ]) : BelongsTo
Parameters
$related : string
$foreignKey : string = null
$ownerKey : string = null
$relation : string = null
Return values
BelongsTo

belongsToMany()

Define a many-to-many relationship.

public belongsToMany(string $related[, string $table = null ][, string $foreignPivotKey = null ][, string $relatedPivotKey = null ][, string $parentKey = null ][, string $relatedKey = null ][, string $relation = null ]) : BelongsToMany
Parameters
$related : string
$table : string = null
$foreignPivotKey : string = null
$relatedPivotKey : string = null
$parentKey : string = null
$relatedKey : string = null
$relation : string = null
Return values
BelongsToMany

getActualClassNameForMorph()

Retrieve the actual class name for a given morph class.

public static getActualClassNameForMorph(string $class) : string
Parameters
$class : string
Return values
string

getMorphClass()

Get the class name for polymorphic relations.

public getMorphClass() : string
Return values
string

getRelation()

Get a specified relationship.

public getRelation(string $relation) : mixed
Parameters
$relation : string
Return values
mixed

getRelations()

Get all the loaded relations for the instance.

public getRelations() : array<string|int, mixed>
Return values
array<string|int, mixed>

getTouchedRelations()

Get the relationships that are touched on save.

public getTouchedRelations() : array<string|int, mixed>
Return values
array<string|int, mixed>

hasMany()

Define a one-to-many relationship.

public hasMany(string $related[, string $foreignKey = null ][, string $localKey = null ]) : HasMany
Parameters
$related : string
$foreignKey : string = null
$localKey : string = null
Return values
HasMany

hasManyThrough()

Define a has-many-through relationship.

public hasManyThrough(string $related, string $through[, string|null $firstKey = null ][, string|null $secondKey = null ][, string|null $localKey = null ][, string|null $secondLocalKey = null ]) : HasManyThrough
Parameters
$related : string
$through : string
$firstKey : string|null = null
$secondKey : string|null = null
$localKey : string|null = null
$secondLocalKey : string|null = null
Return values
HasManyThrough

hasOne()

Define a one-to-one relationship.

public hasOne(string $related[, string $foreignKey = null ][, string $localKey = null ]) : HasOne
Parameters
$related : string
$foreignKey : string = null
$localKey : string = null
Return values
HasOne

joiningTable()

Get the joining table name for a many-to-many relation.

public joiningTable(string $related) : string
Parameters
$related : string
Return values
string

morphedByMany()

Define a polymorphic, inverse many-to-many relationship.

public morphedByMany(string $related, string $name[, string $table = null ][, string $foreignPivotKey = null ][, string $relatedPivotKey = null ][, string $parentKey = null ][, string $relatedKey = null ]) : MorphToMany
Parameters
$related : string
$name : string
$table : string = null
$foreignPivotKey : string = null
$relatedPivotKey : string = null
$parentKey : string = null
$relatedKey : string = null
Return values
MorphToMany

morphMany()

Define a polymorphic one-to-many relationship.

public morphMany(string $related, string $name[, string $type = null ][, string $id = null ][, string $localKey = null ]) : MorphMany
Parameters
$related : string
$name : string
$type : string = null
$id : string = null
$localKey : string = null
Return values
MorphMany

morphOne()

Define a polymorphic one-to-one relationship.

public morphOne(string $related, string $name[, string $type = null ][, string $id = null ][, string $localKey = null ]) : MorphOne
Parameters
$related : string
$name : string
$type : string = null
$id : string = null
$localKey : string = null
Return values
MorphOne

morphTo()

Define a polymorphic, inverse one-to-one or many relationship.

public morphTo([string $name = null ][, string $type = null ][, string $id = null ]) : MorphTo
Parameters
$name : string = null
$type : string = null
$id : string = null
Return values
MorphTo

morphToMany()

Define a polymorphic many-to-many relationship.

public morphToMany(string $related, string $name[, string $table = null ][, string $foreignPivotKey = null ][, string $relatedPivotKey = null ][, string $parentKey = null ][, string $relatedKey = null ][, bool $inverse = false ]) : MorphToMany
Parameters
$related : string
$name : string
$table : string = null
$foreignPivotKey : string = null
$relatedPivotKey : string = null
$parentKey : string = null
$relatedKey : string = null
$inverse : bool = false
Return values
MorphToMany

relationLoaded()

Determine if the given relation is loaded.

public relationLoaded(string $key) : bool
Parameters
$key : string
Return values
bool

setRelation()

Set the specific relationship in the model.

public setRelation(string $relation, mixed $value) : $this
Parameters
$relation : string
$value : mixed
Return values
$this

setRelations()

Set the entire relations array on the model.

public setRelations(array<string|int, mixed> $relations) : $this
Parameters
$relations : array<string|int, mixed>
Return values
$this

setTouchedRelations()

Set the relationships that are touched on save.

public setTouchedRelations(array<string|int, mixed> $touches) : $this
Parameters
$touches : array<string|int, mixed>
Return values
$this

touches()

Determine if the model touches a given relation.

public touches(string $relation) : bool
Parameters
$relation : string
Return values
bool

touchOwners()

Touch the owning relations of the model.

public touchOwners() : void
Return values
void

getMorphs()

Get the polymorphic relationship columns.

protected getMorphs(string $name, string $type, string $id) : array<string|int, mixed>
Parameters
$name : string
$type : string
$id : string
Return values
array<string|int, mixed>

guessBelongsToManyRelation()

Get the relationship name of the belongs to many.

protected guessBelongsToManyRelation() : string
Return values
string

guessBelongsToRelation()

Guess the "belongs to" relationship name.

protected guessBelongsToRelation() : string
Return values
string

morphEagerTo()

Define a polymorphic, inverse one-to-one or many relationship.

protected morphEagerTo(string $name, string $type, string $id) : MorphTo
Parameters
$name : string
$type : string
$id : string
Return values
MorphTo

morphInstanceTo()

Define a polymorphic, inverse one-to-one or many relationship.

protected morphInstanceTo(string $target, string $name, string $type, string $id) : MorphTo
Parameters
$target : string
$name : string
$type : string
$id : string
Return values
MorphTo

newBelongsTo()

Instantiate a new BelongsTo relationship.

protected newBelongsTo(Builder $query, Model $child, string $foreignKey, string $ownerKey, string $relation) : BelongsTo
Parameters
$query : Builder
$child : Model
$foreignKey : string
$ownerKey : string
$relation : string
Return values
BelongsTo

newBelongsToMany()

Instantiate a new BelongsToMany relationship.

protected newBelongsToMany(Builder $query, Model $parent, string $table, string $foreignPivotKey, string $relatedPivotKey, string $parentKey, string $relatedKey[, string $relationName = null ]) : BelongsToMany
Parameters
$query : Builder
$parent : Model
$table : string
$foreignPivotKey : string
$relatedPivotKey : string
$parentKey : string
$relatedKey : string
$relationName : string = null
Return values
BelongsToMany

newHasMany()

Instantiate a new HasMany relationship.

protected newHasMany(Builder $query, Model $parent, string $foreignKey, string $localKey) : HasMany
Parameters
$query : Builder
$parent : Model
$foreignKey : string
$localKey : string
Return values
HasMany

newHasManyThrough()

Instantiate a new HasManyThrough relationship.

protected newHasManyThrough(Builder $query, Model $farParent, Model $throughParent, string $firstKey, string $secondKey, string $localKey, string $secondLocalKey) : HasManyThrough
Parameters
$query : Builder
$farParent : Model
$throughParent : Model
$firstKey : string
$secondKey : string
$localKey : string
$secondLocalKey : string
Return values
HasManyThrough

newHasOne()

Instantiate a new HasOne relationship.

protected newHasOne(Builder $query, Model $parent, string $foreignKey, string $localKey) : HasOne
Parameters
$query : Builder
$parent : Model
$foreignKey : string
$localKey : string
Return values
HasOne

newMorphMany()

Instantiate a new MorphMany relationship.

protected newMorphMany(Builder $query, Model $parent, string $type, string $id, string $localKey) : MorphMany
Parameters
$query : Builder
$parent : Model
$type : string
$id : string
$localKey : string
Return values
MorphMany

newMorphOne()

Instantiate a new MorphOne relationship.

protected newMorphOne(Builder $query, Model $parent, string $type, string $id, string $localKey) : MorphOne
Parameters
$query : Builder
$parent : Model
$type : string
$id : string
$localKey : string
Return values
MorphOne

newMorphTo()

Instantiate a new MorphTo relationship.

protected newMorphTo(Builder $query, Model $parent, string $foreignKey, string $ownerKey, string $type, string $relation) : MorphTo
Parameters
$query : Builder
$parent : Model
$foreignKey : string
$ownerKey : string
$type : string
$relation : string
Return values
MorphTo

newMorphToMany()

Instantiate a new HasManyThrough relationship.

protected newMorphToMany(Builder $query, Model $parent, string $name, string $table, string $foreignPivotKey, string $relatedPivotKey, string $parentKey, string $relatedKey[, string $relationName = null ][, bool $inverse = false ]) : MorphToMany
Parameters
$query : Builder
$parent : Model
$name : string
$table : string
$foreignPivotKey : string
$relatedPivotKey : string
$parentKey : string
$relatedKey : string
$relationName : string = null
$inverse : bool = false
Return values
MorphToMany

newRelatedInstance()

Create a new model instance for a related model.

protected newRelatedInstance(string $class) : mixed
Parameters
$class : string
Return values
mixed

Search results