trait HasRelationships

Properties

protected array $relations

The loaded relationships for the model.

protected array $touches

The relationships that should be touched on save.

static array $manyMethods

The many to many relationship methods.

Methods

hasOne(string $related, string $foreignKey = null, string $localKey = null)

Define a one-to-one relationship.

morphOne(string $related, string $name, string $type = null, string $id = null, string $localKey = null)

Define a polymorphic one-to-one relationship.

belongsTo(string $related, string $foreignKey = null, string $ownerKey = null, string $relation = null)

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

morphTo(string $name = null, string $type = null, string $id = null)

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

morphEagerTo(string $name, string $type, string $id)

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

morphInstanceTo(string $target, string $name, string $type, string $id)

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

static string
getActualClassNameForMorph(string $class)

Retrieve the actual class name for a given morph class.

string
guessBelongsToRelation()

Guess the "belongs to" relationship name.

hasMany(string $related, string $foreignKey = null, string $localKey = null)

Define a one-to-many relationship.

hasManyThrough(string $related, string $through, string|null $firstKey = null, string|null $secondKey = null, string|null $localKey = null)

Define a has-many-through relationship.

morphMany(string $related, string $name, string $type = null, string $id = null, string $localKey = null)

Define a polymorphic one-to-many relationship.

belongsToMany(string $related, string $table = null, string $foreignKey = null, string $relatedKey = null, string $relation = null)

Define a many-to-many relationship.

morphToMany(string $related, string $name, string $table = null, string $foreignKey = null, string $relatedKey = null, bool $inverse = false)

Define a polymorphic many-to-many relationship.

morphedByMany(string $related, string $name, string $table = null, string $foreignKey = null, string $relatedKey = null)

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

string
guessBelongsToManyRelation()

Get the relationship name of the belongs to many.

string
joiningTable(string $related)

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

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.

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 specific relationship in the model.

$this
setRelations(array $relations)

Set the entire relations array on the model.

array
getTouchedRelations()

Get the relationships that are touched on save.

$this
setTouchedRelations(array $touches)

Set the relationships that are touched on save.

Details

at line 54
HasOne hasOne(string $related, string $foreignKey = null, string $localKey = null)

Define a one-to-one relationship.

Parameters

string $related
string $foreignKey
string $localKey

Return Value

HasOne

at line 75
MorphOne morphOne(string $related, string $name, string $type = null, string $id = null, string $localKey = null)

Define a polymorphic one-to-one relationship.

Parameters

string $related
string $name
string $type
string $id
string $localKey

Return Value

MorphOne

at line 97
BelongsTo belongsTo(string $related, string $foreignKey = null, string $ownerKey = null, string $relation = null)

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

Parameters

string $related
string $foreignKey
string $ownerKey
string $relation

Return Value

BelongsTo

at line 133
MorphTo morphTo(string $name = null, string $type = null, string $id = null)

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

Parameters

string $name
string $type
string $id

Return Value

MorphTo

at line 160
protected MorphTo morphEagerTo(string $name, string $type, string $id)

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

Parameters

string $name
string $type
string $id

Return Value

MorphTo

at line 176
protected MorphTo morphInstanceTo(string $target, string $name, string $type, string $id)

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

Parameters

string $target
string $name
string $type
string $id

Return Value

MorphTo

at line 193
static string getActualClassNameForMorph(string $class)

Retrieve the actual class name for a given morph class.

Parameters

string $class

Return Value

string

at line 203
protected string guessBelongsToRelation()

Guess the "belongs to" relationship name.

Return Value

string

at line 218
HasMany hasMany(string $related, string $foreignKey = null, string $localKey = null)

Define a one-to-many relationship.

Parameters

string $related
string $foreignKey
string $localKey

Return Value

HasMany

at line 241
HasManyThrough hasManyThrough(string $related, string $through, string|null $firstKey = null, string|null $secondKey = null, string|null $localKey = null)

Define a has-many-through relationship.

Parameters

string $related
string $through
string|null $firstKey
string|null $secondKey
string|null $localKey

Return Value

HasManyThrough

at line 266
MorphMany morphMany(string $related, string $name, string $type = null, string $id = null, string $localKey = null)

Define a polymorphic one-to-many relationship.

Parameters

string $related
string $name
string $type
string $id
string $localKey

Return Value

MorphMany

at line 292
BelongsToMany belongsToMany(string $related, string $table = null, string $foreignKey = null, string $relatedKey = null, string $relation = null)

Define a many-to-many relationship.

Parameters

string $related
string $table
string $foreignKey
string $relatedKey
string $relation

Return Value

BelongsToMany

at line 333
MorphToMany morphToMany(string $related, string $name, string $table = null, string $foreignKey = null, string $relatedKey = null, bool $inverse = false)

Define a polymorphic many-to-many relationship.

Parameters

string $related
string $name
string $table
string $foreignKey
string $relatedKey
bool $inverse

Return Value

MorphToMany

at line 367
MorphToMany morphedByMany(string $related, string $name, string $table = null, string $foreignKey = null, string $relatedKey = null)

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

Parameters

string $related
string $name
string $table
string $foreignKey
string $relatedKey

Return Value

MorphToMany

at line 384
protected string guessBelongsToManyRelation()

Get the relationship name of the belongs to many.

Return Value

string

at line 399
string joiningTable(string $related)

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

Parameters

string $related

Return Value

string

at line 423
bool touches(string $relation)

Determine if the model touches a given relation.

Parameters

string $relation

Return Value

bool

at line 433
void touchOwners()

Touch the owning relations of the model.

Return Value

void

at line 458
protected array getMorphs(string $name, string $type, string $id)

Get the polymorphic relationship columns.

Parameters

string $name
string $type
string $id

Return Value

array

at line 468
string getMorphClass()

Get the class name for polymorphic relations.

Return Value

string

at line 485
protected mixed newRelatedInstance(string $class)

Create a new model instance for a related model.

Parameters

string $class

Return Value

mixed

at line 499
array getRelations()

Get all the loaded relations for the instance.

Return Value

array

at line 510
mixed getRelation(string $relation)

Get a specified relationship.

Parameters

string $relation

Return Value

mixed

at line 521
bool relationLoaded(string $key)

Determine if the given relation is loaded.

Parameters

string $key

Return Value

bool

at line 533
$this setRelation(string $relation, mixed $value)

Set the specific relationship in the model.

Parameters

string $relation
mixed $value

Return Value

$this

at line 546
$this setRelations(array $relations)

Set the entire relations array on the model.

Parameters

array $relations

Return Value

$this

at line 558
array getTouchedRelations()

Get the relationships that are touched on save.

Return Value

array

at line 569
$this setTouchedRelations(array $touches)

Set the relationships that are touched on save.

Parameters

array $touches

Return Value

$this