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.

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.

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.

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 36
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 63
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 83
protected Builder setKeysForSelectQuery(Builder $query)

Set the keys for a select query.

Parameters

Builder $query

Return Value

Builder

at line 106
protected Builder setKeysForSaveQuery(Builder $query)

Set the keys for a save update query.

Parameters

Builder $query

Return Value

Builder

at line 117
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 141
protected Builder getDeleteQuery()

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

Return Value

Builder

at line 152
string getTable()

Get the table associated with the model.

Return Value

string

at line 168
string getForeignKey()

Get the foreign key column name.

Return Value

string

at line 176
string getRelatedKey()

Get the "related key" column name.

Return Value

string

at line 184
string getOtherKey()

Get the "related key" column name.

Return Value

string

at line 194
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 208
AsPivot setRelatedModel(Model|null $related = null)

Set the related model of the relationship.

Parameters

Model|null $related

Return Value

AsPivot

at line 218
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 227
string|null getCreatedAtColumn()

Get the name of the "created at" column.

Return Value

string|null

at line 237
string|null getUpdatedAtColumn()

Get the name of the "updated at" column.

Return Value

string|null

at line 247
mixed getQueueableId()

Get the queueable identity for the entity.

Return Value

mixed

at line 267
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 290
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 317
AsPivot unsetRelations()

Unset all the loaded relations for the instance.

Return Value

AsPivot