Spec-Zone.ru › Laravel 9

HasRelationships

trait HasRelationships (View source)

Свойства

protected массив $relations

Загруженные отношения для модели.

protected массив $touches

Отношения, которые должны быть обновлены при сохранении.

static массив строк $manyMethods

Методы отношений «многие ко многим».

static protected массив $relationResolvers

Обратные вызовы для разрешения отношений.

Методы

mixed relationResolver(string $class, string $key)

Получить динамический разрешитель отношений, если он определен или унаследован, в противном случае вернуть null.

static void resolveRelationUsing(string $name, Closure $callback)

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

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

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

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

Инициализировать новое отношение один-к-одному.

HasOneThrough hasOneThrough(string $related, string $through, string|null $firstKey = null, string|null $secondKey = null, string|null $localKey = null, string|null $secondLocalKey = null)

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

HasOneThrough newHasOneThrough(Builder $query, Model $farParent, Model $throughParent, string $firstKey, string $secondKey, string $localKey, string $secondLocalKey)

Инициализировать новое отношение один-через-много.

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

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

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

Инициализировать новое полиморфное отношение один-к-одному.

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

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

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

Инициализировать новое обратное отношение один-к-одному.

MorphTo morphTo(string|null $name = null, string|null $type = null, string|null $id = null, string|null $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)

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

static string getActualClassNameForMorph(string $class)

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

string guessBelongsToRelation()

Предположить имя отношения "belongs to".

PendingHasThroughRelationship through(string|HasMany|HasOne $relationship)

Создать ожидаемое отношение "has-many-through" или "has-one-through".

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

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

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

Инициализировать новое отношение один-ко-многим.

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

Определить отношение "has-many-through".

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

Инициализировать новое отношение "has-many-through".

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

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

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

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

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

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

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

Инициализировать новое отношение многие-ко-многим.

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)

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

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

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

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)

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

string|null guessBelongsToManyRelation()

Получить имя отношения belongsToMany.

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)

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

mixed newRelatedThroughInstance(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)

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

$this withoutRelations()

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

$this unsetRelations()

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

array getTouchedRelations()

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

$this setTouchedRelations(array $touches)

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

Подробности

mixed relationResolver(string $class, string $key)

Получить динамический решатель отношений, если он определен или унаследован, или вернуть null.

Параметры

string $class
string $key

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

mixed

static void resolveRelationUsing(string $name, Closure $callback)

Определить динамический решатель отношений.

Параметры

string $name
Closure $callback

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

void

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

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

Параметры

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

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

HasOne

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

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

Параметры

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

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

HasOne

HasOneThrough hasOneThrough(string $related, string $through, string|null $firstKey = null, string|null $secondKey = null, string|null $localKey = null, string|null $secondLocalKey = null)

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

Параметры

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

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

HasOneThrough
END_OF_DOCUMENT_MARKER

protected HasOneThrough newHasOneThrough(Builder $query, Model $farParent, Model $throughParent, string $firstKey, string $secondKey, string $localKey, string $secondLocalKey)

Создать новую связь HasOneThrough.

Параметры

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

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

HasOneThrough

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

Определить полиморфную связь один-к-одному.

Параметры

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

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

MorphOne

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

Инициализировать новую полиморфную связь один-к-одному.

Параметры

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

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

MorphOne

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

Определить обратную связь один-к-одному или один-ко-многим.

Параметры

string $related
string|null $foreignKey
string|null $ownerKey
string|null $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|null $name = null, string|null $type = null, string|null $id = null, string|null $ownerKey = null)

Определить полиморфную, обратную связь один-к-одному или один-ко-многим.

Параметры

string|null $name
string|null $type
string|null $id
string|null $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)

Определить полиморфную, обратную связь один-к-одному или один-ко-многим.

Параметры

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

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

MorphTo

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

Инициализировать новую полиморфную связь MorphTo.

Параметры

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

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

MorphTo

static string getActualClassNameForMorph(string $class)

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

Параметры

string $class

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

string

protected string guessBelongsToRelation()

Угадать имя связи "belongs to".

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

string

PendingHasThroughRelationship through(string|HasMany|HasOne $relationship)

Создать ожидаемое отношение has-many-through или has-one-through.

Параметры

string|HasMany|HasOne $relationship

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

PendingHasThroughRelationship

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

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

Параметры

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

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

HasMany

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

Инициализация нового отношения один-ко-многим.

Параметры

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)

Определение отношения has-many-through.

Параметры

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

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

HasManyThrough

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

Инициализация нового отношения HasManyThrough.

Параметры

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

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

HasManyThrough

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

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

Параметры

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

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

MorphMany

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

Инициализация нового полиморфного отношения один-ко-многим.

Параметры

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

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

MorphMany

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

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

Параметры

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

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

BelongsToMany

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

Инициализация нового отношения многие-ко-многим.

Параметры

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

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

BelongsToMany

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)

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

Параметры

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

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

MorphToMany

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

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

Параметры

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

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

MorphToMany

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)

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

Параметры

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

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

MorphToMany

protected string|null guessBelongsToManyRelation()

Получить имя отношения belongsToMany.

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

string|null

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

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

Параметры

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

protected mixed newRelatedThroughInstance(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

$this withoutRelations()

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

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

$this

$this unsetRelations()

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

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

$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/9.x/Illuminate/Database/Eloquent/Concerns/HasRelationships.html

Spec-Zone.ru

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