Documentation

InteractsWithPivotTable

Table of Contents

attach()  : void
Attach a model to the parent.
detach()  : int
Detach models from the relationship.
newExistingPivot()  : Pivot
Create a new existing pivot model instance.
newPivot()  : Pivot
Create a new pivot model instance.
newPivotStatement()  : Builder
Get a new plain query builder for the pivot table.
newPivotStatementForId()  : Builder
Get a new pivot statement for a given "other" ID.
sync()  : array<string|int, mixed>
Sync the intermediate tables with a list of IDs or collection of models.
syncWithoutDetaching()  : array<string|int, mixed>
Sync the intermediate tables with a list of IDs without detaching.
toggle()  : array<string|int, mixed>
Toggles a model (or models) from the parent.
updateExistingPivot()  : int
Update an existing pivot record on the table.
withPivot()  : $this
Set the columns on the pivot table to retrieve.
addTimestampsToAttachment()  : array<string|int, mixed>
Set the creation and update timestamps on an attach record.
attachNew()  : array<string|int, mixed>
Attach all of the records that aren't in the given current records.
baseAttachRecord()  : array<string|int, mixed>
Create a new pivot attachment record.
castAttributes()  : array<string|int, mixed>
Cast the given pivot attributes.
castKey()  : mixed
Cast the given key to an integer if it is numeric.
castKeys()  : array<string|int, mixed>
Cast the given keys to integers if they are numeric and string otherwise.
extractAttachIdAndAttributes()  : array<string|int, mixed>
Get the attach record ID and extra attributes.
formatAttachRecord()  : array<string|int, mixed>
Create a full attachment record payload.
formatAttachRecords()  : array<string|int, mixed>
Create an array of records to insert into the pivot table.
formatRecordsList()  : array<string|int, mixed>
Format the sync / toggle record list so that it is keyed by ID.
hasPivotColumn()  : bool
Determine whether the given column is defined as a pivot column.
newPivotQuery()  : Builder
Create a new query builder for the pivot table.
parseIds()  : array<string|int, mixed>
Get all of the IDs from the given mixed value.

Methods

attach()

Attach a model to the parent.

public attach(mixed $id[, array<string|int, mixed> $attributes = [] ][, bool $touch = true ]) : void
Parameters
$id : mixed
$attributes : array<string|int, mixed> = []
$touch : bool = true
Return values
void

detach()

Detach models from the relationship.

public detach([mixed $ids = null ][, bool $touch = true ]) : int
Parameters
$ids : mixed = null
$touch : bool = true
Return values
int

newExistingPivot()

Create a new existing pivot model instance.

public newExistingPivot([array<string|int, mixed> $attributes = [] ]) : Pivot
Parameters
$attributes : array<string|int, mixed> = []
Return values
Pivot

newPivot()

Create a new pivot model instance.

public newPivot([array<string|int, mixed> $attributes = [] ][, bool $exists = false ]) : Pivot
Parameters
$attributes : array<string|int, mixed> = []
$exists : bool = false
Return values
Pivot

newPivotStatementForId()

Get a new pivot statement for a given "other" ID.

public newPivotStatementForId(mixed $id) : Builder
Parameters
$id : mixed
Return values
Builder

sync()

Sync the intermediate tables with a list of IDs or collection of models.

public sync(Collection|Collection|array<string|int, mixed> $ids[, bool $detaching = true ]) : array<string|int, mixed>
Parameters
$ids : Collection|Collection|array<string|int, mixed>
$detaching : bool = true
Return values
array<string|int, mixed>

syncWithoutDetaching()

Sync the intermediate tables with a list of IDs without detaching.

public syncWithoutDetaching(Collection|Collection|array<string|int, mixed> $ids) : array<string|int, mixed>
Parameters
$ids : Collection|Collection|array<string|int, mixed>
Return values
array<string|int, mixed>

toggle()

Toggles a model (or models) from the parent.

public toggle(mixed $ids[, bool $touch = true ]) : array<string|int, mixed>

Each existing model is detached, and non existing ones are attached.

Parameters
$ids : mixed
$touch : bool = true
Return values
array<string|int, mixed>

updateExistingPivot()

Update an existing pivot record on the table.

public updateExistingPivot(mixed $id, array<string|int, mixed> $attributes[, bool $touch = true ]) : int
Parameters
$id : mixed
$attributes : array<string|int, mixed>
$touch : bool = true
Return values
int

withPivot()

Set the columns on the pivot table to retrieve.

public withPivot(array<string|int, mixed>|mixed $columns) : $this
Parameters
$columns : array<string|int, mixed>|mixed
Return values
$this

addTimestampsToAttachment()

Set the creation and update timestamps on an attach record.

protected addTimestampsToAttachment(array<string|int, mixed> $record[, bool $exists = false ]) : array<string|int, mixed>
Parameters
$record : array<string|int, mixed>
$exists : bool = false
Return values
array<string|int, mixed>

attachNew()

Attach all of the records that aren't in the given current records.

protected attachNew(array<string|int, mixed> $records, array<string|int, mixed> $current[, bool $touch = true ]) : array<string|int, mixed>
Parameters
$records : array<string|int, mixed>
$current : array<string|int, mixed>
$touch : bool = true
Return values
array<string|int, mixed>

baseAttachRecord()

Create a new pivot attachment record.

protected baseAttachRecord(int $id, bool $timed) : array<string|int, mixed>
Parameters
$id : int
$timed : bool
Return values
array<string|int, mixed>

castAttributes()

Cast the given pivot attributes.

protected castAttributes(array<string|int, mixed> $attributes) : array<string|int, mixed>
Parameters
$attributes : array<string|int, mixed>
Return values
array<string|int, mixed>

castKey()

Cast the given key to an integer if it is numeric.

protected castKey(mixed $key) : mixed
Parameters
$key : mixed
Return values
mixed

castKeys()

Cast the given keys to integers if they are numeric and string otherwise.

protected castKeys(array<string|int, mixed> $keys) : array<string|int, mixed>
Parameters
$keys : array<string|int, mixed>
Return values
array<string|int, mixed>

extractAttachIdAndAttributes()

Get the attach record ID and extra attributes.

protected extractAttachIdAndAttributes(mixed $key, mixed $value, array<string|int, mixed> $attributes) : array<string|int, mixed>
Parameters
$key : mixed
$value : mixed
$attributes : array<string|int, mixed>
Return values
array<string|int, mixed>

formatAttachRecord()

Create a full attachment record payload.

protected formatAttachRecord(int $key, mixed $value, array<string|int, mixed> $attributes, bool $hasTimestamps) : array<string|int, mixed>
Parameters
$key : int
$value : mixed
$attributes : array<string|int, mixed>
$hasTimestamps : bool
Return values
array<string|int, mixed>

formatAttachRecords()

Create an array of records to insert into the pivot table.

protected formatAttachRecords(array<string|int, mixed> $ids, array<string|int, mixed> $attributes) : array<string|int, mixed>
Parameters
$ids : array<string|int, mixed>
$attributes : array<string|int, mixed>
Return values
array<string|int, mixed>

formatRecordsList()

Format the sync / toggle record list so that it is keyed by ID.

protected formatRecordsList(array<string|int, mixed> $records) : array<string|int, mixed>
Parameters
$records : array<string|int, mixed>
Return values
array<string|int, mixed>

hasPivotColumn()

Determine whether the given column is defined as a pivot column.

protected hasPivotColumn(string $column) : bool
Parameters
$column : string
Return values
bool

parseIds()

Get all of the IDs from the given mixed value.

protected parseIds(mixed $value) : array<string|int, mixed>
Parameters
$value : mixed
Return values
array<string|int, mixed>

Search results