Spec-Zone.ru › Laravel 5.8

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)

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

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 $type = null, string $id = null, string $localKey = null)

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

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

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

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)

Инициализировать новое отношение принадлежности.

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)

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

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)

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

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 $type = null, string $id = null, string $localKey = null)

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

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

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

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)

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

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 morphedByMany(string $related, string $name, string $table = null, string $foreignPivotKey = null, string $relatedPivotKey = null, string $parentKey = null, string $relatedKey = null)

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

string|null guessBelongsToManyRelation()

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

string joiningTable(string $related, Модель|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, Модель $parent, string $foreignKey, string $localKey)

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

Параметры

Builder $query
Модель $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)

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

Параметры

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

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

HasOneThrough

protected HasOneThrough newHasOneThrough(Builder $query, Модель $farParent, Модель $throughParent, string $firstKey, string $secondKey, string $localKey, string $secondLocalKey)

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

Параметры

Builder $query
Модель $farParent
Модель $throughParent
string $firstKey
string $secondKey
string $localKey
string $secondLocalKey

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

HasOneThrough

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, Модель $parent, string $type, string $id, string $localKey)

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

Параметры

Builder $query
Модель $parent
string $type
string $id
string $localKey

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

MorphOne
END_OF_DOCUMENT_MARKER

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)

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

Параметры

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

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

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

string

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

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

Параметры

string $related
string $foreignKey
string $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)

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

Параметры

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

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

HasManyThrough
END_OF_DOCUMENT_MARKER

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 $type = null, string $id = null, string $localKey = null)

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

Параметры

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

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

Параметры

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

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

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)

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

Параметры

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

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

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

string|null

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

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

Parameters

string $related
Model|null $instance

Return Value

string

string joiningTableSegment()

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

Return Value

string

bool touches(string $relation)

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

Parameters

string $relation

Return Value

bool

void touchOwners()

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

Return Value

void

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

Получить столбцы полиморфной связи.

Parameters

string $name
string $type
string $id

Return Value

array

string getMorphClass()

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

Return Value

string

protected mixed newRelatedInstance(string $class)

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

Parameters

string $class

Return Value

mixed

array getRelations()

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

Return Value

array

mixed getRelation(string $relation)

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

Parameters

string $relation

Return Value

mixed

bool relationLoaded(string $key)

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

Parameters

string $key

Return Value

bool

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

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

Parameters

string $relation
mixed $value

Return Value

$this

$this unsetRelation(string $relation)

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

Parameters

string $relation

Return Value

$this

$this setRelations(array $relations)

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

Parameters

array $relations

Return Value

$this

array getTouchedRelations()

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

Return Value

array

$this setTouchedRelations(array $touches)

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

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

Spec-Zone.ru

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