W3cubDocs

/Laravel 5.4

InteractsWithPivotTable

trait InteractsWithPivotTable (View source)

Methods

array toggle(mixed $ids, bool $touch = true)

Toggles a model (or models) from the parent.

array syncWithoutDetaching(Collection|array $ids)

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

array sync(Collection|Collection|array $ids, bool $detaching = true)

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

int updateExistingPivot(mixed $id, array $attributes, bool $touch = true)

Update an existing pivot record on the table.

void attach(mixed $id, array $attributes = array(), bool $touch = true)

Attach a model to the parent.

int detach(mixed $ids = null, bool $touch = true)

Detach models from the relationship.

Pivot newPivot(array $attributes = array(), bool $exists = false)

Create a new pivot model instance.

Pivot newExistingPivot(array $attributes = array())

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.

$this withPivot(array|mixed $columns)

Set the columns on the pivot table to retrieve.

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.

Parameters

mixed $ids
bool $touch

Return Value

array

array syncWithoutDetaching(Collection|array $ids)

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

Parameters

Collection|array $ids

Return Value

array

array sync(Collection|Collection|array $ids, bool $detaching = true)

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

Parameters

Collection|Collection|array $ids
bool $detaching

Return Value

array

int updateExistingPivot(mixed $id, array $attributes, bool $touch = true)

Update an existing pivot record on the table.

Parameters

mixed $id
array $attributes
bool $touch

Return Value

int

void attach(mixed $id, array $attributes = array(), bool $touch = true)

Attach a model to the parent.

Parameters

mixed $id
array $attributes
bool $touch

Return Value

void

int detach(mixed $ids = null, bool $touch = true)

Detach models from the relationship.

Parameters

mixed $ids
bool $touch

Return Value

int

Pivot newPivot(array $attributes = array(), bool $exists = false)

Create a new pivot model instance.

Parameters

array $attributes
bool $exists

Return Value

Pivot

Pivot newExistingPivot(array $attributes = array())

Create a new existing pivot model instance.

Parameters

array $attributes

Return Value

Pivot

Builder newPivotStatement()

Get a new plain query builder for the pivot table.

Return Value

Builder

Builder newPivotStatementForId(mixed $id)

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

Parameters

mixed $id

Return Value

Builder

$this withPivot(array|mixed $columns)

Set the columns on the pivot table to retrieve.

Parameters

array|mixed $columns

Return Value

$this

© Taylor Otwell
Licensed under the MIT License.
Laravel is a trademark of Taylor Otwell.
https://laravel.com/api/5.4/Illuminate/Database/Eloquent/Relations/Concerns/InteractsWithPivotTable.html