HasRelationships (Database\Eloquent\Concerns)

HasRelationships

trait HasRelationships (View source)

Properties

static array $manyMethods The many to many relationship methods.

Methods

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

Define a one-to-one relationship.

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

Define a polymorphic one-to-one relationship.

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

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

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

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.

HasMany hasMany(string $related, string $foreignKey = null, string $localKey = 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)

Define a has-many-through relationship.

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

Define a polymorphic one-to-many relationship.

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

Define a many-to-many relationship.

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.

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

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

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.

string getMorphClass()

Get the class name for polymorphic relations.

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

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

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

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

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

static string getActualClassNameForMorph(string $class)

Retrieve the actual class name for a given morph class.

Parameters

string $class

Return Value

string

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

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

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

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

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

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

string joiningTable(string $related)

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

Parameters

string $related

Return Value

string

bool touches(string $relation)

Determine if the model touches a given relation.

Parameters

string $relation

Return Value

bool

void touchOwners()

Touch the owning relations of the model.

Return Value

void

string getMorphClass()

Get the class name for polymorphic relations.

Return Value

string

array getRelations()

Get all the loaded relations for the instance.

Return Value

array

mixed getRelation(string $relation)

Get a specified relationship.

Parameters

string $relation

Return Value

mixed

bool relationLoaded(string $key)

Determine if the given relation is loaded.

Parameters

string $key

Return Value

bool

$this setRelation(string $relation, mixed $value)

Set the specific relationship in the model.

Parameters

string $relation
mixed $value

Return Value

$this

$this setRelations(array $relations)

Set the entire relations array on the model.

Parameters

array $relations

Return Value

$this

array getTouchedRelations()

Get the relationships that are touched on save.

Return Value

array

$this setTouchedRelations(array $touches)

Set the relationships that are touched on save.

Parameters

array $touches

Return Value

$this

© Taylor Otwell
Licensed under the MIT License.
Laravel is a trademark of Taylor Otwell.
https://laravel.com/api/5.4/Illuminate/Database/Eloquent/Concerns/HasRelationships.html

在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号

意见反馈
返回顶部