trait AsPivot

Properties

Model|null $pivotParent

The parent model of the relationship.

Model|null $pivotRelated

The related model of the relationship.

protected string $foreignKey

The name of the foreign key column.

protected string $relatedKey

The name of the "other key" column.

protected null|list<array{string, array<int, mixed>}> $pivotConstraints

The relation-owned predicates that identify this pivot row.

Methods

static AsPivot
fromAttributes(Model $parent, array $attributes, string $table, bool $exists = false)

Create a new pivot model instance.

static AsPivot
fromRawAttributes(Model $parent, array $attributes, string $table, bool $exists = false)

Create a new pivot model from raw values returned from a query.

setKeysForSelectQuery(Builder $query)

Set the keys for a select query.

setKeysForSaveQuery(Builder $query)

Set the keys for a save update query.

int
delete()

Delete the pivot model record from the database.

getDeleteQuery()

Get the query builder for a delete operation on the pivot.

applyPivotConstraints(Builder $query)

Apply the relation-owned predicates to a pivot identity query.

mixed
getPivotKeyForQuery(string $column)

Get a pivot key for a query.

string
getTable()

Get the table associated with the model.

string
getForeignKey()

Get the foreign key column name.

string
getRelatedKey()

Get the "related key" column name.

string
getOtherKey()

Get the "related key" column name.

setPivotKeys(string $foreignKey, string $relatedKey)

Set the key names for the pivot model instance.

setPivotConstraints(array $constraints)

Set the relation-owned predicates for the pivot model.

setRelatedModel(Model|null $related = null)

Set the related model of the relationship.

bool
hasTimestampAttributes(array|null $attributes = null)

Determine if the pivot model or given attributes has timestamp attributes.

string|null
getCreatedAtColumn()

Get the name of the "created at" column.

string|null
getUpdatedAtColumn()

Get the name of the "updated at" column.

mixed
getQueueableId()

Get the queueable identity for the entity.

newQueryForRestoration(array|int|string $ids)

Get a new query to restore one or more models by their queueable IDs.

newQueryForCollectionRestoration(array $ids)

Get a new query to restore multiple models by their queueable IDs.

unsetRelations()

Unset all the loaded relations for the instance.

Details

at line 44
static AsPivot fromAttributes(Model $parent, array $attributes, string $table, bool $exists = false)

Create a new pivot model instance.

Parameters

Model $parent
array $attributes
string $table
bool $exists

Return Value

AsPivot

at line 71
static AsPivot fromRawAttributes(Model $parent, array $attributes, string $table, bool $exists = false)

Create a new pivot model from raw values returned from a query.

Parameters

Model $parent
array $attributes
string $table
bool $exists

Return Value

AsPivot

at line 91
protected Builder setKeysForSelectQuery(Builder $query)

Set the keys for a select query.

Parameters

Builder $query

Return Value

Builder

at line 110
protected Builder setKeysForSaveQuery(Builder $query)

Set the keys for a save update query.

Parameters

Builder $query

Return Value

Builder

at line 121
int delete()

Delete the pivot model record from the database.

Returns affected row count (int) rather than bool|null because pivots use query builder deletion with compound keys.

Return Value

int

at line 145
protected Builder getDeleteQuery()

Get the query builder for a delete operation on the pivot.

Return Value

Builder

at line 161
protected Builder applyPivotConstraints(Builder $query)

Apply the relation-owned predicates to a pivot identity query.

Parameters

Builder $query

Return Value

Builder

at line 179
protected mixed getPivotKeyForQuery(string $column)

Get a pivot key for a query.

Parameters

string $column

Return Value

mixed

Exceptions

MissingAttributeException

at line 193
string getTable()

Get the table associated with the model.

Return Value

string

at line 209
string getForeignKey()

Get the foreign key column name.

Return Value

string

at line 217
string getRelatedKey()

Get the "related key" column name.

Return Value

string

at line 225
string getOtherKey()

Get the "related key" column name.

Return Value

string

at line 235
AsPivot setPivotKeys(string $foreignKey, string $relatedKey)

Set the key names for the pivot model instance.

Parameters

string $foreignKey
string $relatedKey

Return Value

AsPivot

at line 250
AsPivot setPivotConstraints(array $constraints)

Set the relation-owned predicates for the pivot model.

Parameters

array $constraints

Return Value

AsPivot

at line 262
AsPivot setRelatedModel(Model|null $related = null)

Set the related model of the relationship.

Parameters

Model|null $related

Return Value

AsPivot

at line 272
bool hasTimestampAttributes(array|null $attributes = null)

Determine if the pivot model or given attributes has timestamp attributes.

Parameters

array|null $attributes

Return Value

bool

at line 281
string|null getCreatedAtColumn()

Get the name of the "created at" column.

Return Value

string|null

at line 291
string|null getUpdatedAtColumn()

Get the name of the "updated at" column.

Return Value

string|null

at line 303
mixed getQueueableId()

Get the queueable identity for the entity.

Return Value

mixed

Exceptions

MissingAttributeException

at line 323
Builder newQueryForRestoration(array|int|string $ids)

Get a new query to restore one or more models by their queueable IDs.

Parameters

array|int|string $ids

Return Value

Builder

at line 346
protected Builder newQueryForCollectionRestoration(array $ids)

Get a new query to restore multiple models by their queueable IDs.

Parameters

array $ids

Return Value

Builder

at line 373
AsPivot unsetRelations()

Unset all the loaded relations for the instance.

Return Value

AsPivot