InteractsWithPivotTable
trait InteractsWithPivotTable
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.
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.
Attach a model to the parent.
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.
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.
Cast the given keys to integers if they are numeric and string otherwise.
Cast the given key to an integer if it is numeric.
Details
at line 20
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 70
array
syncWithoutDetaching(Collection|array $ids)
Sync the intermediate tables with a list of IDs without detaching.
at line 82
array
sync(Collection|Collection|array $ids, bool $detaching = true)
Sync the intermediate tables with a list of IDs or collection of models.
at line 132
protected array
formatRecordsList(array $records)
Format the sync / toggle record list so that it is keyed by ID.
at line 151
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 185
int
updateExistingPivot(mixed $id, array $attributes, bool $touch = true)
Update an existing pivot record on the table.
at line 208
void
attach(mixed $id, array $attributes = [], bool $touch = true)
Attach a model to the parent.
at line 229
protected array
formatAttachRecords(array $ids, array $attributes)
Create an array of records to insert into the pivot table.
at line 257
protected array
formatAttachRecord(int $key, mixed $value, array $attributes, bool $hasTimestamps)
Create a full attachment record payload.
at line 274
protected array
extractAttachIdAndAttributes(mixed $key, mixed $value, array $attributes)
Get the attach record ID and extra attributes.
at line 288
protected array
baseAttachRecord(int $id, bool $timed)
Create a new pivot attachment record.
at line 311
protected array
addTimestampsToAttachment(array $record, bool $exists = false)
Set the creation and update timestamps on an attach record.
at line 332
protected bool
hasPivotColumn(string $column)
Determine whether the given column is defined as a pivot column.
at line 344
int
detach(mixed $ids = null, bool $touch = true)
Detach models from the relationship.
at line 380
Pivot
newPivot(array $attributes = [], bool $exists = false)
Create a new pivot model instance.
at line 395
Pivot
newExistingPivot(array $attributes = [])
Create a new existing pivot model instance.
at line 405
Builder
newPivotStatement()
Get a new plain query builder for the pivot table.
at line 416
Builder
newPivotStatementForId(mixed $id)
Get a new pivot statement for a given "other" ID.
at line 426
protected Builder
newPivotQuery()
Create a new query builder for the pivot table.
at line 447
$this
withPivot(array|mixed $columns)
Set the columns on the pivot table to retrieve.
at line 462
protected array
parseIds(mixed $value)
Get all of the IDs from the given mixed value.
at line 485
protected array
castKeys(array $keys)
Cast the given keys to integers if they are numeric and string otherwise.
at line 498
protected mixed
castKey(mixed $key)
Cast the given key to an integer if it is numeric.