InteractsWithPivotTable
trait InteractsWithPivotTable
Methods
Toggles a model (or models) from the parent.
Toggle a model (or models) from the parent within a transaction.
Sync the intermediate tables with a list of IDs without detaching.
Sync the intermediate tables with a list of IDs or collection of models.
Sync the intermediate tables with a list of IDs or collection of models within a transaction.
Sync the intermediate tables with a list of IDs without detaching within a transaction.
Sync the intermediate tables with a list of IDs or collection of models with the given pivot values.
Sync the intermediate tables with a list of IDs or collection of models with the given pivot values within a transaction.
Format the sync / toggle record list so that it is keyed by ID.
Attach all of the records that aren't in the given current records.
Update an existing pivot record on the table.
Update an existing pivot record on the table within a transaction.
Update an existing pivot record on the table via a custom class.
Attach a model to the parent.
Attach a model to the parent within a transaction.
Attach a model to the parent using a custom class.
Create an array of records to insert into the pivot table.
Create a full attachment record payload.
Get the attach record ID and extra attributes.
Create a new pivot attachment record.
Set the creation and update timestamps on an attach record.
Determine whether the given column is defined as a pivot column.
Detach models from the relationship.
Detach models from the relationship within a transaction.
Detach models from the relationship using a custom class.
Get the pivot models that are currently attached.
Get the pivot models that are currently attached, filtered by related model keys.
Create a new existing pivot model instance.
Get a new plain query builder for the pivot table.
Get the connection that owns the pivot table.
Get a new pivot statement for a given "other" ID.
Create a new query builder for the pivot table.
Determine whether the relation has pivot constraints.
Set the columns on the pivot table to retrieve.
Get all of the IDs from the given mixed value.
Get the ID from the given mixed value.
Cast the given keys to integers if they are numeric and string otherwise.
Cast the given key to convert to primary key type.
Cast the given pivot attributes.
Converts a given value to a given type value.
Details
at line 24
array
toggle(mixed $ids, bool $touch = true)
Toggles a model (or models) from the parent.
Each existing model is detached, and non existing ones are attached.
at line 73
array
toggleOrFail(mixed $ids, bool $touch = true)
Toggle a model (or models) from the parent within a transaction.
at line 83
array
syncWithoutDetaching(Collection|Model|array|int|string|null $ids)
Sync the intermediate tables with a list of IDs without detaching.
at line 93
array
sync(Collection|Model|array|int|string|null $ids, bool $detaching = true)
Sync the intermediate tables with a list of IDs or collection of models.
at line 151
array
syncOrFail(Collection|Model|array|int|string|null $ids, bool $detaching = true)
Sync the intermediate tables with a list of IDs or collection of models within a transaction.
at line 163
array
syncWithoutDetachingOrFail(Collection|Model|array|int|string|null $ids)
Sync the intermediate tables with a list of IDs without detaching within a transaction.
at line 173
array
syncWithPivotValues(Collection|Model|array|int|string|null $ids, array $values, bool $detaching = true)
Sync the intermediate tables with a list of IDs or collection of models with the given pivot values.
at line 187
array
syncWithPivotValuesOrFail(Collection|Model|array|int|string|null $ids, array $values, bool $detaching = true)
Sync the intermediate tables with a list of IDs or collection of models with the given pivot values within a transaction.
at line 195
protected array
formatRecordsList(array $records)
Format the sync / toggle record list so that it is keyed by ID.
at line 211
protected array
attachNew(array $records, array $current, bool $touch = true)
Attach all of the records that aren't in the given current records.
at line 240
int
updateExistingPivot(mixed $id, array $attributes, bool $touch = true)
Update an existing pivot record on the table.
at line 266
int
updateExistingPivotOrFail(mixed $id, array $attributes, bool $touch = true)
Update an existing pivot record on the table within a transaction.
at line 274
protected int
updateExistingPivotUsingCustomClass(mixed $id, array $attributes, bool $touch)
Update an existing pivot record on the table via a custom class.
at line 294
void
attach(mixed $ids, array $attributes = [], bool $touch = true)
Attach a model to the parent.
at line 318
void
attachOrFail(mixed $ids, array $attributes = [], bool $touch = true)
Attach a model to the parent within a transaction.
at line 326
protected void
attachUsingCustomClass(mixed $ids, array $attributes)
Attach a model to the parent using a custom class.
at line 341
protected array
formatAttachRecords(array $ids, array $attributes)
Create an array of records to insert into the pivot table.
at line 366
protected array
formatAttachRecord(int|string $key, mixed $value, array $attributes, bool $hasTimestamps)
Create a full attachment record payload.
at line 379
protected array
extractAttachIdAndAttributes(mixed $key, mixed $value, array $attributes)
Get the attach record ID and extra attributes.
at line 389
protected array
baseAttachRecord(mixed $id, bool $timed)
Create a new pivot attachment record.
at line 412
protected array
addTimestampsToAttachment(array $record, bool $exists = false)
Set the creation and update timestamps on an attach record.
at line 436
bool
hasPivotColumn(string|null $column)
Determine whether the given column is defined as a pivot column.
at line 444
int
detach(mixed $ids = null, bool $touch = true)
Detach models from the relationship.
at line 482
int
detachOrFail(mixed $ids = null, bool $touch = true)
Detach models from the relationship within a transaction.
at line 490
protected int
detachUsingCustomClass(mixed $ids)
Detach models from the relationship using a custom class.
at line 499
protected Collection
getCurrentlyAttachedPivots()
Get the pivot models that are currently attached.
at line 507
protected Collection
getCurrentlyAttachedPivotsForIds(mixed $ids = null)
Get the pivot models that are currently attached, filtered by related model keys.
at line 521
Model
newPivot(array $attributes = [], bool $exists = false)
Create a new pivot model instance.
at line 558
Model
newExistingPivot(array $attributes = [])
Create a new existing pivot model instance.
at line 566
Builder
newPivotStatement()
Get a new plain query builder for the pivot table.
at line 574
protected ConnectionInterface
getPivotConnection()
Get the connection that owns the pivot table.
at line 582
Builder
newPivotStatementForId(mixed $id)
Get a new pivot statement for a given "other" ID.
at line 590
Builder
newPivotQuery()
Create a new query builder for the pivot table.
at line 608
protected bool
hasPivotConstraints()
Determine whether the relation has pivot constraints.
at line 618
InteractsWithPivotTable
withPivot(mixed $columns)
Set the columns on the pivot table to retrieve.
at line 631
protected array
parseIds(mixed $value)
Get all of the IDs from the given mixed value.
at line 653
protected mixed
parseId(mixed $value)
Get the ID from the given mixed value.
at line 661
protected array
castKeys(array $keys)
Cast the given keys to integers if they are numeric and string otherwise.
at line 671
protected mixed
castKey(mixed $key)
Cast the given key to convert to primary key type.
at line 682
protected array
castAttributes(array $attributes)
Cast the given pivot attributes.
at line 692
protected mixed
getTypeSwapValue(string $type, mixed $value)
Converts a given value to a given type value.