Spec-Zone.ru › Laravel 10

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

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

PendingHasThroughRelationship through(string|HasMany|HasOne $relationship)

Создать ожидаемое отношение многие-ко-многим или один-к-многим через посредника.

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)

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

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

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

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|Model>|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|Model> $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, string|null $relation = 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 $relation = 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.

Parameters

string $class
string $key

Return Value

mixed

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

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

Parameters

string $name
Closure $callback

Return Value

void

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

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

Parameters

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

Return Value

HasOne

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

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

Parameters

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

Return Value

HasOne

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

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

Parameters

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

Return Value

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)

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

Параметры

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)

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

Параметры

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)

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

Параметры

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

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

MorphMany

BelongsToMany belongsToMany(string $related, string|Model>|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|Model>|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|Model> $table, string $foreignPivotKey, string $relatedPivotKey, string $parentKey, string $relatedKey, string|null $relationName = null)

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

Параметры

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

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

BelongsToMany
END_OF_DOCUMENT_MARKER

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, string|null $relation = null, bool $inverse = false)

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

Параметры

string $related
string $name
string|null $table
string|null $foreignPivotKey
string|null $relatedPivotKey
string|null $parentKey
string|null $relatedKey
string|null $relation
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)

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

Параметры

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|null $relation = null)

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

Параметры

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

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

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)

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

Параметры

массив $relations

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

$this

$this withoutRelations()

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

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

$this

$this unsetRelations()

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

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

$this

array getTouchedRelations()

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

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

массив

$this setTouchedRelations(array $touches)

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

Параметры

массив $touches

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

$this

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

Spec-Zone.ru

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