InteractsWithPivotTable
trait InteractsWithPivotTable (View source)
Methods
Toggles a model (or models) from the parent.
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 with the given pivot values.
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 via a custom class.
Attach a model to the parent.
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 using a custom class.
Get the pivot models that are currently attached.
Create a new existing pivot model instance.
Get a new plain query builder for the pivot table.
Get a new pivot statement for a given "other" ID.
Create a new query builder for the pivot table.
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
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.
array
syncWithoutDetaching(Collection|Model|array $ids)
Sync the intermediate tables with a list of IDs without detaching.
array
sync(Collection|Model|array $ids, bool $detaching = true)
Sync the intermediate tables with a list of IDs or collection of models.
array
syncWithPivotValues(Collection|Model|array $ids, array $values, bool $detaching = true)
Sync the intermediate tables with a list of IDs or collection of models with the given pivot values.
protected array
formatRecordsList(array $records)
Format the sync / toggle record list so that it is keyed by ID.
protected array
attachNew(array $records, array $current, bool $touch = true)
Attach all of the records that aren't in the given current records.
int
updateExistingPivot(mixed $id, array $attributes, bool $touch = true)
Update an existing pivot record on the table.
protected int
updateExistingPivotUsingCustomClass(mixed $id, array $attributes, bool $touch)
Update an existing pivot record on the table via a custom class.
void
attach(mixed $id, array $attributes = [], bool $touch = true)
Attach a model to the parent.
protected void
attachUsingCustomClass(mixed $id, array $attributes)
Attach a model to the parent using a custom class.
protected array
formatAttachRecords(array $ids, array $attributes)
Create an array of records to insert into the pivot table.
protected array
formatAttachRecord(int $key, mixed $value, array $attributes, bool $hasTimestamps)
Create a full attachment record payload.
protected array
extractAttachIdAndAttributes(mixed $key, mixed $value, array $attributes)
Get the attach record ID and extra attributes.
protected array
baseAttachRecord(int $id, bool $timed)
Create a new pivot attachment record.
protected array
addTimestampsToAttachment(array $record, bool $exists = false)
Set the creation and update timestamps on an attach record.
bool
hasPivotColumn(string $column)
Determine whether the given column is defined as a pivot column.
int
detach(mixed $ids = null, bool $touch = true)
Detach models from the relationship.
protected int
detachUsingCustomClass(mixed $ids)
Detach models from the relationship using a custom class.
protected Collection
getCurrentlyAttachedPivots()
Get the pivot models that are currently attached.
Pivot
newPivot(array $attributes = [], bool $exists = false)
Create a new pivot model instance.
Pivot
newExistingPivot(array $attributes = [])
Create a new existing pivot model instance.
Builder
newPivotStatement()
Get a new plain query builder for the pivot table.
Builder
newPivotStatementForId(mixed $id)
Get a new pivot statement for a given "other" ID.
Builder
newPivotQuery()
Create a new query builder for the pivot table.
$this
withPivot(array|mixed $columns)
Set the columns on the pivot table to retrieve.
protected array
parseIds(mixed $value)
Get all of the IDs from the given mixed value.
protected mixed
parseId(mixed $value)
Get the ID from the given mixed value.
protected array
castKeys(array $keys)
Cast the given keys to integers if they are numeric and string otherwise.
protected mixed
castKey(mixed $key)
Cast the given key to convert to primary key type.
protected array
castAttributes(array $attributes)
Cast the given pivot attributes.
protected mixed
getTypeSwapValue(string $type, mixed $value)
Converts a given value to a given type value.