Spec-Zone.ru › Laravel 5.7

HasRelationships

trait HasRelationships (View source)

Свойства

protected массив $relations Загруженные отношения для модели.
protected массив $touches Отношения, которые следует обновлять при сохранении.
static массив $manyMethods Методы отношений «многие ко многим».

Методы

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

Определить отношение «один-к-одному».

HasOne newHasOne(Builder $query, Model $parent, string $foreignKey, string $localKey)

Создать новое отношение HasOne.

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

Определить полиморфное отношение «один-к-одному».

MorphOne newMorphOne(Builder $query, Model $parent, string $type, string $id, string $localKey)

Создать новое полиморфное отношение MorphOne.

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

Определить обратное отношение «один-к-одному» или «многие-к-одному».

BelongsTo newBelongsTo(Builder $query, Model $child, string $foreignKey, string $ownerKey, string $relation)

Создать новое отношение BelongsTo.

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

Определить полиморфное, обратное отношение «один-к-одному» или «многие-к-одному».

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

Определить полиморфное, обратное отношение «один-к-одному» или «многие-к-одному».

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

Определить полиморфное, обратное отношение «один-к-одному» или «многие-к-одному».

MorphTo newMorphTo(Builder $query, Model $parent, string $foreignKey, string $ownerKey, string $type, string $relation)

Создать новое отношение MorphTo.

static string getActualClassNameForMorph(string $class)

Получить фактическое имя класса для заданного морф-класса.

string guessBelongsToRelation()

Угадать имя отношения «принадлежит к».

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

Определить отношение «один-ко-многим».

HasMany newHasMany(Builder $query, Model $parent, string $foreignKey, string $localKey)

Создать новое отношение HasMany.

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

Определить отношение «многие-через-многие».

HasManyThrough newHasManyThrough(Builder $query, Model $farParent, Model $throughParent, string $firstKey, string $secondKey, string $localKey, string $secondLocalKey)

Создать новое отношение HasManyThrough.

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

Определить полиморфное отношение «один-ко-многим».

MorphMany newMorphMany(Builder $query, Model $parent, string $type, string $id, string $localKey)

Создать новое полиморфное отношение MorphMany.

BelongsToMany belongsToMany(string $related, string $table = null, string $foreignPivotKey = null, string $relatedPivotKey = null, string $parentKey = null, string $relatedKey = null, string $relation = null)

Определить отношение «многие-ко-многим».

BelongsToMany newBelongsToMany(Builder $query, Model $parent, string $table, string $foreignPivotKey, string $relatedPivotKey, string $parentKey, string $relatedKey, string $relationName = null)

Создать новое отношение BelongsToMany.

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

Определить полиморфное отношение «многие-ко-многим».

MorphToMany newMorphToMany(Builder $query, Model $parent, string $name, string $table, string $foreignPivotKey, string $relatedPivotKey, string $parentKey, string $relatedKey, string $relationName = null, bool $inverse = false)

Создать новое полиморфное отношение MorphToMany.

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

Определить полиморфное, обратное отношение «многие-ко-многим».

string guessBelongsToManyRelation()

Получить имя отношения «многие-ко-многим».

string joiningTable(string $related, Model|null $instance = null)

Получить имя таблицы соединения для отношения «многие-ко-многим».

string joiningTableSegment()

Получить часть имени промежуточной таблицы для отношений belongsToMany для этой модели.

bool touches(string $relation)

Определить, касается ли модель заданного отношения.

void touchOwners()

Коснуться владеющих отношений модели.

array getMorphs(string $name, string $type, string $id)

Получить столбцы полиморфных отношений.

string getMorphClass()

Получить имя класса для полиморфных отношений.

mixed newRelatedInstance(string $class)

Создать новый экземпляр модели для связанной модели.

array getRelations()

Получить все загруженные отношения для экземпляра.

mixed getRelation(string $relation)

Получить указанное отношение.

bool relationLoaded(string $key)

Определить, загружено ли заданное отношение.

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

Установить заданное отношение в модели.

$this unsetRelation(string $relation)

Удалить загруженное отношение.

$this setRelations(array $relations)

Установить весь массив отношений в модели.

array getTouchedRelations()

Получить отношения, которые касаются сохранения.

$this setTouchedRelations(array $touches)

Установить отношения, которые касаются сохранения.

Подробности

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

Определить отношение один к одному.

Параметры

string $related
string $foreignKey
string $localKey

Значение результата

HasOne

protected HasOne newHasOne(Builder $query, Model $parent, string $foreignKey, string $localKey)

Инициализировать новое отношение HasOne.

Параметры

Builder $query
Model $parent
string $foreignKey
string $localKey

Значение результата

HasOne

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

Определить полиморфное отношение один к одному.

Параметры

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

Значение результата

MorphOne

protected MorphOne newMorphOne(Builder $query, Model $parent, string $type, string $id, string $localKey)

Инициализировать новое полиморфное отношение MorphOne.

Параметры

Builder $query
Model $parent
string $type
string $id
string $localKey

Значение результата

MorphOne

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

Определить обратное отношение один-к-одному или многим.

Параметры

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

Значение результата

BelongsTo

protected BelongsTo newBelongsTo(Builder $query, Model $child, string $foreignKey, string $ownerKey, string $relation)

Инициализировать новое отношение BelongsTo.

Параметры

Builder $query
Model $child
string $foreignKey
string $ownerKey
string $relation

Значение результата

BelongsTo

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

Определить полиморфное, обратное отношение один-к-одному или многим.

Параметры

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

Значение результата

MorphTo

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

Определить полиморфное, обратное отношение один-к-одному или многим.

Параметры

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

Значение результата

MorphTo

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

Определите полиморфное, обратное одно-к-одному или многие-ко-одному отношение.

Parameters

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

Return Value

MorphTo

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

Инициализируйте новое отношение MorphTo.

Parameters

Builder $query
Model $parent
string $foreignKey
string $ownerKey
string $type
string $relation

Return Value

MorphTo

static string getActualClassNameForMorph(string $class)

Получить фактическое имя класса для данного класса morph.

Parameters

string $class

Return Value

string

protected string guessBelongsToRelation()

Угадать имя отношения «принадлежит».

Return Value

string

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

Определите отношение один-ко-многим.

Parameters

string $related
string $foreignKey
string $localKey

Return Value

HasMany

protected HasMany newHasMany(Builder $query, Model $parent, string $foreignKey, string $localKey)

Инициализируйте новое отношение HasMany.

Parameters

Builder $query
Model $parent
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, string|null $secondLocalKey = null)

Определите отношение многие-ко-многим через.

Parameters

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

Return Value

HasManyThrough

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

Инициализируйте новое отношение HasManyThrough.

Parameters

Builder $query
Model $farParent
Model $throughParent
string $firstKey
string $secondKey
string $localKey
string $secondLocalKey

Return Value

HasManyThrough

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

Определите полиморфное отношение один-ко-многим.

Parameters

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

Return Value

MorphMany

protected MorphMany newMorphMany(Builder $query, Model $parent, string $type, string $id, string $localKey)

Инициализируйте новое отношение MorphMany.

Parameters

Builder $query
Model $parent
string $type
string $id
string $localKey

Return Value

MorphMany

BelongsToMany belongsToMany(string $related, string $table = null, string $foreignPivotKey = null, string $relatedPivotKey = null, string $parentKey = null, string $relatedKey = null, string $relation = null)

Определите отношение многие-ко-многим.

Parameters

string $related
string $table
string $foreignPivotKey
string $relatedPivotKey
string $parentKey
string $relatedKey
string $relation

Return Value

BelongsToMany

protected BelongsToMany newBelongsToMany(Builder $query, Model $parent, string $table, string $foreignPivotKey, string $relatedPivotKey, string $parentKey, string $relatedKey, string $relationName = null)

Создать новое отношение BelongsToMany.

Параметры

Builder $query
Model $parent
string $table
string $foreignPivotKey
string $relatedPivotKey
string $parentKey
string $relatedKey
string $relationName

Возвращаемое значение

BelongsToMany

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

Определить полиморфное много-ко-многие отношение.

Параметры

string $related
string $name
string $table
string $foreignPivotKey
string $relatedPivotKey
string $parentKey
string $relatedKey
bool $inverse

Возвращаемое значение

MorphToMany

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

Создать новое полиморфное много-ко-многие отношение.

Параметры

Builder $query
Model $parent
string $name
string $table
string $foreignPivotKey
string $relatedPivotKey
string $parentKey
string $relatedKey
string $relationName
bool $inverse

Возвращаемое значение

MorphToMany

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

Определить полиморфное обратное много-ко-многие отношение.

Параметры

string $related
string $name
string $table
string $foreignPivotKey
string $relatedPivotKey
string $parentKey
string $relatedKey

Возвращаемое значение

MorphToMany

protected string guessBelongsToManyRelation()

Получить имя отношения belongs to many.

Возвращаемое значение

string

string joiningTable(string $related, Model|null $instance = null)

Получить имя таблицы соединения для отношения many-to-many.

Параметры

string $related
Model|null $instance

Возвращаемое значение

string

string joiningTableSegment()

Получить часть имени промежуточной таблицы для отношений belongsToMany.

Возвращаемое значение

string

bool touches(string $relation)

Определить, касается ли модель заданное отношение.

Параметры

string $relation

Возвращаемое значение

bool

void touchOwners()

Обновить связанные отношения модели.

Возвращаемое значение

void

protected array getMorphs(string $name, string $type, string $id)

Получить столбцы полиморфного отношения.

Параметры

string $name
string $type
string $id

Возвращаемое значение

array

string getMorphClass()

Получить имя класса для полиморфных отношений.

Возвращаемое значение

string

protected mixed newRelatedInstance(string $class)

Создать новый экземпляр модели для связанной модели.

Параметры

string $class

Возвращаемое значение

mixed

array getRelations()

Получить все загруженные отношения для экземпляра.

Возвращаемое значение

array

mixed getRelation(string $relation)

Получить заданное отношение.

Параметры

string $relation

Возвращаемое значение

mixed

bool relationLoaded(string $key)

Определить, загружено ли данное отношение.

Параметры

string $key

Возвращаемое значение

bool

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

Установить заданное отношение для модели.

Параметры

string $relation
mixed $value

Возвращаемое значение

$this

$this unsetRelation(string $relation)

Удалить загруженное отношение.

Параметры

string $relation

Возвращаемое значение

$this

$this setRelations(array $relations)

Установить весь массив отношений для модели.

Параметры

array $relations

Возвращаемое значение

$this

array getTouchedRelations()

Получить отношения, которые затрагиваются при сохранении.

Возвращаемое значение

array

$this setTouchedRelations(array $touches)

Установить отношения, которые затрагиваются при сохранении.

Параметры

array $touches

Возвращаемое значение

$this

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

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API