trait HasRelationships

Properties

$relation

The loaded relationships for the model.

static protected array $relationTypes

Methods

hasRelation($name)

No description

array
getRelationDefinition(string $name)

Returns relationship details from a supplied name.

array
getRelationDefinitions()

Returns relationship details for all relations defined on this model.

string
getRelationType(string $name)

Returns a relationship type based on a supplied name.

mixed
getRelationValue(string $key)

Get a relationship.

$this
setRelationValue($relationName, $value)

Sets a relation value directly from its attribute.

string
makeRelation(string $name)

Returns a relation class object

bool
isRelationPushable(string $name)

Determines whether the specified relation should be saved when push() is called instead of save() on the model. Default: true.

array
getRelationDefaults(string $type)

Returns default relation arguments for a given type.

handleRelation($relationName)

No description

array
validateRelationArgs($relationName, $optional, array $required = [])

Validate relation supplied arguments.

HasOne
hasOne(string $related, string|null $foreignKey = null, string|null $localKey = null, null $relationName = null)

Define a one-to-one relationship.

hasOneThrough($related, $through, $primaryKey = null, $throughKey = null, $localKey = null, $secondLocalKey = null, $relationName = null)

Define a has-one-through relationship.

HasMany
hasMany(string $related, string|null $foreignKey = null, string|null $localKey = null, null $relationName = null)

Define a one-to-many relationship.

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

Define a has-many-through relationship.

belongsTo($related, $foreignKey = null, $ownerKey = null, $relationName = null)

No description

belongsToMany($related, $table = null, $foreignPivotKey = null, $relatedPivotKey = null, $parentKey = null, $relatedKey = null, $relationName = null)

No description

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

Define a polymorphic one-to-one relationship.

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

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

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

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

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

Define a polymorphic one-to-many relationship.

morphToMany(string $related, string $name, string|null $table = null, string|null $foreignPivotKey = null, string|null $relatedPivotKey = null, string|null $parentKey = null, string|null $relatedKey = null, bool $inverse = false, null $relationName = null)

Define a polymorphic many-to-many relationship.

morphedByMany(string $related, string $name, string|null $table = null, string|null $foreignPivotKey = null, string|null $relatedPivotKey = null, string|null $parentKey = null, string|null $relatedKey = null, null $relationName = null)

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

Details

at line 58
hasRelation($name)

No description

Parameters

$name

at line 70
array getRelationDefinition(string $name)

Returns relationship details from a supplied name.

Parameters

string $name

Relation name

Return Value

array

at line 81
array getRelationDefinitions()

Returns relationship details for all relations defined on this model.

Return Value

array

at line 108
string getRelationType(string $name)

Returns a relationship type based on a supplied name.

Parameters

string $name

Relation name

Return Value

string

at line 124
mixed getRelationValue(string $key)

Get a relationship.

Parameters

string $key

Return Value

mixed

at line 141
protected $this setRelationValue($relationName, $value)

Sets a relation value directly from its attribute.

Parameters

$relationName
$value

Return Value

$this

at line 155
string makeRelation(string $name)

Returns a relation class object

Parameters

string $name

Relation name

Return Value

string

at line 177
bool isRelationPushable(string $name)

Determines whether the specified relation should be saved when push() is called instead of save() on the model. Default: true.

Parameters

string $name

Relation name

Return Value

bool

at line 194
protected array getRelationDefaults(string $type)

Returns default relation arguments for a given type.

Parameters

string $type

Relation type

Return Value

array

at line 206
handleRelation($relationName)

No description

Parameters

$relationName

at line 334
protected array validateRelationArgs($relationName, $optional, array $required = [])

Validate relation supplied arguments.

Parameters

$relationName
$optional
array $required

Return Value

array

at line 374
HasOne hasOne(string $related, string|null $foreignKey = null, string|null $localKey = null, null $relationName = null)

Define a one-to-one relationship.

Parameters

string $related
string|null $foreignKey
string|null $localKey
null $relationName

Return Value

HasOne

at line 398
HasOneThrough hasOneThrough($related, $through, $primaryKey = null, $throughKey = null, $localKey = null, $secondLocalKey = null, $relationName = null)

Define a has-one-through relationship.

This code is a duplicate of Eloquent but uses a Rain relation class.

Parameters

$related
$through
$primaryKey
$throughKey
$localKey
$secondLocalKey
$relationName

Return Value

HasOneThrough

at line 428
HasMany hasMany(string $related, string|null $foreignKey = null, string|null $localKey = null, null $relationName = null)

Define a one-to-many relationship.

Parameters

string $related
string|null $foreignKey
string|null $localKey
null $relationName

Return Value

HasMany

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

Define a has-many-through relationship.

Parameters

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

Return Value

HasManyThrough

at line 487
belongsTo($related, $foreignKey = null, $ownerKey = null, $relationName = null)

No description

Parameters

$related
$foreignKey
$ownerKey
$relationName

at line 508
belongsToMany($related, $table = null, $foreignPivotKey = null, $relatedPivotKey = null, $parentKey = null, $relatedKey = null, $relationName = null)

No description

Parameters

$related
$table
$foreignPivotKey
$relatedPivotKey
$parentKey
$relatedKey
$relationName

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

Define a polymorphic one-to-one relationship.

Parameters

string $related
string $name
string|null $type
string|null $id
string|null $localKey
null $relationName

Return Value

MorphOne

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

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

Parameters

string $name
string $type
string $id
$ownerKey

Return Value

MorphTo

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

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

Parameters

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

Return Value

MorphTo

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

Define a polymorphic one-to-many relationship.

Parameters

string $related
string $name
string|null $type
string|null $id
string|null $localKey
null $relationName

Return Value

MorphMany

at line 657
MorphToMany morphToMany(string $related, string $name, string|null $table = null, string|null $foreignPivotKey = null, string|null $relatedPivotKey = null, string|null $parentKey = null, string|null $relatedKey = null, bool $inverse = false, null $relationName = null)

Define a polymorphic many-to-many relationship.

Parameters

string $related
string $name
string|null $table
string|null $foreignPivotKey
string|null $relatedPivotKey
string|null $parentKey
string|null $relatedKey
bool $inverse
null $relationName

Return Value

MorphToMany

at line 705
MorphToMany morphedByMany(string $related, string $name, string|null $table = null, string|null $foreignPivotKey = null, string|null $relatedPivotKey = null, string|null $parentKey = null, string|null $relatedKey = null, null $relationName = null)

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

Parameters

string $related
string $name
string|null $table
string|null $foreignPivotKey
string|null $relatedPivotKey
string|null $parentKey
string|null $relatedKey
null $relationName

Return Value

MorphToMany