Documentation

BelongsToMany extends BelongsToMany
in package
Uses DeferOneOrMany, DefinedConstraints

Table of Contents

$countMode  : bool
$morphMap  : array<string|int, mixed>
An array to map class names to their morph names in database.
$orphanMode  : bool
$withTimestamps  : bool
Indicates if timestamps are available on the pivot table.
$accessor  : string
The name of the accessor to use for the "pivot" relationship.
$constraints  : bool
Indicates if the relation is adding constraints.
$foreignPivotKey  : string
The foreign key of the parent model.
$macros  : array<string|int, mixed>
The registered string macros.
$parent  : Model
The parent model instance.
$parentKey  : string
The key name of the parent model.
$pivotColumns  : array<string|int, mixed>
The pivot table columns to retrieve.
$pivotCreatedAt  : string
The custom pivot table column for the created_at timestamp.
$pivotUpdatedAt  : string
The custom pivot table column for the updated_at timestamp.
$pivotWhereIns  : array<string|int, mixed>
Any pivot table restrictions for whereIn clauses.
$pivotWheres  : array<string|int, mixed>
Any pivot table restrictions for where clauses.
$query  : Builder
The Eloquent query builder instance.
$related  : Model
The related model instance.
$relatedKey  : string
The key name of the related model.
$relatedPivotKey  : string
The associated key of the relation.
$relationName  : string
The "name" of the relationship.
$selfJoinCount  : int
The count of self joins.
$table  : string
The intermediate table for the relation.
$using  : string
The class name of the custom pivot model to use for the relationship.
__call()  : mixed
Dynamically handle calls to the class.
__callStatic()  : mixed
Dynamically handle calls to the class.
__clone()  : void
Force a clone of the underlying query builder when cloning.
__construct()  : void
Create a new belongs to many relationship instance.
add()  : mixed
Adds a model to this relationship type.
addConstraints()  : void
Set the base constraints on the relation query.
addDefinedConstraints()  : void
Set the defined constraints on the relation query.
addDefinedConstraintsToQuery()  : mixed
Add query based constraints.
addDefinedConstraintsToRelation()  : mixed
Add relation based constraints.
addEagerConstraints()  : void
Set the constraints for an eager load of the relation.
allRelatedIds()  : Collection
Get all of the IDs for the related models, with deferred binding support
as()  : BelongsToMany
Specify the custom pivot accessor to use for the relationship.
attach()  : mixed
Override attach() method of BelongToMany relation.
chunk()  : bool
Chunk the results of the query.
create()  : Model
Create a new instance of this related model with deferred binding support.
createdAt()  : string
Get the name of the "created at" column.
createMany()  : array<string|int, mixed>
Create an array of new instances of the related models.
detach()  : int|void
Override detach() method of BelongToMany relation.
find()  : Model|Collection|null
Find a related model by its primary key.
findMany()  : Collection
Find multiple related models by their primary keys.
findOrFail()  : Model|Collection
Find a related model by its primary key or throw an exception.
findOrNew()  : Collection|Model
Find a related model by its primary key or return new instance of the related model.
first()  : mixed
Execute the query and get the first result.
firstOrCreate()  : Model
Get the first related record matching the attributes or create it.
firstOrFail()  : Model|static
Execute the query and get the first result or throw an exception.
firstOrNew()  : Model
Get the first related model record matching the attributes or instantiate it.
get()  : Collection
Execute the query as a "select" statement.
getBaseQuery()  : Builder
Get the base query builder driving the Eloquent builder.
getEager()  : Collection
Get the relationship for eager loading.
getExistenceCompareKey()  : string
Get the key for comparing against the parent key in "has" query.
getForeignKey()  : string
Get the fully qualified foreign key for the relation.
getForeignPivotKeyName()  : string
Get the foreign key for the relation.
getMorphedModel()  : string|null
Get the model associated with a custom polymorphic type.
getOtherKey()  : string
Get the fully qualified "other key" for the relation.
getParent()  : Model
Get the parent model of the relation.
getPivotAccessor()  : string
Get the name of the pivot accessor for this relationship.
getQualifiedForeignPivotKeyName()  : string
Get the fully qualified foreign key for the relation.
getQualifiedParentKeyName()  : string
Get the fully qualified parent key name.
getQualifiedRelatedPivotKeyName()  : string
Get the fully qualified "related key" for the relation.
getQuery()  : Builder
Get the underlying query for the relation.
getRelated()  : Model
Get the related model of the relation.
getRelatedIds()  : mixed
getRelatedPivotKeyName()  : string
Get the "related key" for the relation.
getRelationCountHash()  : string
Get a relationship join table hash.
getRelationExistenceCountQuery()  : Builder
Add the constraints for a relationship count query.
getRelationExistenceQuery()  : Builder
Add the constraints for an internal relationship existence query.
getRelationExistenceQueryForSelfJoin()  : Builder
Add the constraints for a relationship query on the same table.
getRelationName()  : string
Get the relationship name for the relationship.
getResults()  : mixed
Get the results of the relationship.
getSimpleValue()  : mixed
Helper for getting this relationship simple value, generally useful with form values.
getTable()  : string
Get the intermediate table for the relationship.
hasMacro()  : bool
Checks if macro is registered.
initRelation()  : array<string|int, mixed>
Initialize the relation on a set of models.
macro()  : void
Register a custom macro.
match()  : array<string|int, mixed>
Match the eagerly loaded results to their parents.
mixin()  : void
Mix another object into the class.
morphMap()  : array<string|int, mixed>
Set or get the morph map for polymorphic relations.
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.
noConstraints()  : mixed
Run a callback with constraints disabled on the relation.
orWherePivot()  : BelongsToMany
Set an "or where" clause for a pivot table column.
orWherePivotIn()  : BelongsToMany
Set an "or where in" clause for a pivot table column.
paginate()  : LengthAwarePaginator
Get a paginator for the "select" statement. Complies with October Rain.
rawUpdate()  : int
Run a raw update against the base query.
relatedUpdatedAt()  : string
Get the name of the related model's "updated at" column.
remove()  : mixed
Removes a model from this relationship type.
save()  : Model
Save the supplied related model with deferred binding support.
saveMany()  : array<string|int, mixed>
Save an array of new models and attach them to the parent model.
setSimpleValue()  : mixed
Helper for setting this relationship using various expected values. For example, $model->relation = $value;
simplePaginate()  : Paginator
Paginate the given query into a simple paginator.
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.
touch()  : void
Touch all of the related models for the relationship.
touchIfTouching()  : void
If we're touching the parent model, touch.
updatedAt()  : string
Get the name of the "updated at" column.
updateExistingPivot()  : int
Update an existing pivot record on the table.
updateOrCreate()  : Model
Create or update a related record matching the attributes, and fill it with values.
using()  : BelongsToMany
Specify the custom pivot model to use for the relationship.
wherePivot()  : BelongsToMany
Set a where clause for a pivot table column.
wherePivotIn()  : BelongsToMany
Set a "where in" clause for a pivot table column.
withDeferred()  : Builder
Returns the model query with deferred bindings added
withPivot()  : $this
Set the columns on the pivot table to retrieve.
withTimestamps()  : BelongsToMany
Specify that the pivot table has creation and update timestamps.
addTimestampsToAttachment()  : array<string|int, mixed>
Set the creation and update timestamps on an attach record.
addWhereConstraints()  : $this
Set the where clause for the relation query.
aliasedPivotColumns()  : array<string|int, mixed>
Get the pivot columns for the relation.
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.
buildDictionary()  : array<string|int, mixed>
Build model dictionary keyed by the relation's foreign key.
buildMorphMapFromModels()  : array<string|int, mixed>|null
Builds a table-keyed array from model class names.
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.
getKeys()  : array<string|int, mixed>
Get all of the primary keys for an array of models.
getWithDeferredQualifiedKeyName()  : Expression
Returns the related "slave id" key in a database friendly format.
guessInverseRelation()  : string
Attempt to guess the name of the inverse of the relation.
hasPivotColumn()  : bool
Determine whether the given column is defined as a pivot column.
hydratePivotRelation()  : void
Hydrate the pivot table relationship on the models.
migratePivotAttributes()  : array<string|int, mixed>
Get the pivot attributes from a model.
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.
performJoin()  : $this
Set the join clause for the relation query.
shouldSelect()  : BelongsToMany
Get the select columns for the relation query.
touchingParent()  : bool
Determine if we should touch the parent on sync.

Properties

$countMode

public bool $countMode = false

This relation object is a 'count' helper.

$morphMap

An array to map class names to their morph names in database.

public static array<string|int, mixed> $morphMap = []

$orphanMode

public bool $orphanMode = false

When a join is not used, don't select aliased columns.

$withTimestamps

Indicates if timestamps are available on the pivot table.

public bool $withTimestamps = false

$accessor

The name of the accessor to use for the "pivot" relationship.

protected string $accessor = 'pivot'

$constraints

Indicates if the relation is adding constraints.

protected static bool $constraints = true

$foreignPivotKey

The foreign key of the parent model.

protected string $foreignPivotKey

$macros

The registered string macros.

protected static array<string|int, mixed> $macros = []

$parentKey

The key name of the parent model.

protected string $parentKey

$pivotColumns

The pivot table columns to retrieve.

protected array<string|int, mixed> $pivotColumns = []

$pivotCreatedAt

The custom pivot table column for the created_at timestamp.

protected string $pivotCreatedAt

$pivotUpdatedAt

The custom pivot table column for the updated_at timestamp.

protected string $pivotUpdatedAt

$pivotWhereIns

Any pivot table restrictions for whereIn clauses.

protected array<string|int, mixed> $pivotWhereIns = []

$pivotWheres

Any pivot table restrictions for where clauses.

protected array<string|int, mixed> $pivotWheres = []

$relatedKey

The key name of the related model.

protected string $relatedKey

$relatedPivotKey

The associated key of the relation.

protected string $relatedPivotKey

$relationName

The "name" of the relationship.

protected string $relationName

$selfJoinCount

The count of self joins.

protected static int $selfJoinCount = 0

$table

The intermediate table for the relation.

protected string $table

$using

The class name of the custom pivot model to use for the relationship.

protected string $using

Methods

__call()

Dynamically handle calls to the class.

public __call(string $method, array<string|int, mixed> $parameters) : mixed
Parameters
$method : string
$parameters : array<string|int, mixed>
Tags
throws
BadMethodCallException
Return values
mixed

__callStatic()

Dynamically handle calls to the class.

public static __callStatic(string $method, array<string|int, mixed> $parameters) : mixed
Parameters
$method : string
$parameters : array<string|int, mixed>
Tags
throws
BadMethodCallException
Return values
mixed

__clone()

Force a clone of the underlying query builder when cloning.

public __clone() : void
Return values
void

__construct()

Create a new belongs to many relationship instance.

public __construct(Builder $query, Model $parent, string $table, string $foreignPivotKey, string $relatedPivotKey, mixed $parentKey, mixed $relatedKey[, string $relationName = null ]) : void
Parameters
$query : Builder
$parent : Model
$table : string
$foreignPivotKey : string
$relatedPivotKey : string
$parentKey : mixed
$relatedKey : mixed
$relationName : string = null
Return values
void

add()

Adds a model to this relationship type.

public add(Model $model[, mixed $sessionKey = null ][, mixed $pivotData = [] ]) : mixed
Parameters
$model : Model
$sessionKey : mixed = null
$pivotData : mixed = []
Return values
mixed

addConstraints()

Set the base constraints on the relation query.

public abstract addConstraints() : void
Return values
void

addDefinedConstraints()

Set the defined constraints on the relation query.

public addDefinedConstraints() : void
Return values
void

addDefinedConstraintsToQuery()

Add query based constraints.

public addDefinedConstraintsToQuery(QueryBuilder $query[, array<string|int, mixed> $args = null ]) : mixed
Parameters
$query : QueryBuilder
$args : array<string|int, mixed> = null
Return values
mixed

addDefinedConstraintsToRelation()

Add relation based constraints.

public addDefinedConstraintsToRelation(Relation $relation[, array<string|int, mixed> $args = null ]) : mixed
Parameters
$relation : Relation
$args : array<string|int, mixed> = null
Return values
mixed

addEagerConstraints()

Set the constraints for an eager load of the relation.

public abstract addEagerConstraints(array<string|int, mixed> $models) : void
Parameters
$models : array<string|int, mixed>
Return values
void

allRelatedIds()

Get all of the IDs for the related models, with deferred binding support

public allRelatedIds([string $sessionKey = null ]) : Collection
Parameters
$sessionKey : string = null
Return values
Collection

attach()

Override attach() method of BelongToMany relation.

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

This is necessary in order to fire 'model.relation.beforeAttach', 'model.relation.afterAttach' events

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

chunk()

Chunk the results of the query.

public chunk(int $count, callable $callback) : bool
Parameters
$count : int
$callback : callable
Return values
bool

create()

Create a new instance of this related model with deferred binding support.

public create([array<string|int, mixed> $attributes = [] ][, array<string|int, mixed> $pivotData = [] ][, mixed $sessionKey = null ]) : Model
Parameters
$attributes : array<string|int, mixed> = []
$pivotData : array<string|int, mixed> = []
$sessionKey : mixed = null
Return values
Model

createdAt()

Get the name of the "created at" column.

public createdAt() : string
Return values
string

createMany()

Create an array of new instances of the related models.

public createMany(array<string|int, mixed> $records[, array<string|int, mixed> $joinings = [] ]) : array<string|int, mixed>
Parameters
$records : array<string|int, mixed>
$joinings : array<string|int, mixed> = []
Return values
array<string|int, mixed>

detach()

Override detach() method of BelongToMany relation.

public detach([null $ids = null ][, bool $touch = true ]) : int|void

This is necessary in order to fire 'model.relation.beforeDetach', 'model.relation.afterDetach' events

Parameters
$ids : null = null
$touch : bool = true
Return values
int|void

find()

Find a related model by its primary key.

public find(mixed $id[, array<string|int, mixed> $columns = ['*'] ]) : Model|Collection|null
Parameters
$id : mixed
$columns : array<string|int, mixed> = ['*']
Return values
Model|Collection|null

findMany()

Find multiple related models by their primary keys.

public findMany(mixed $ids[, array<string|int, mixed> $columns = ['*'] ]) : Collection
Parameters
$ids : mixed
$columns : array<string|int, mixed> = ['*']
Return values
Collection

findOrNew()

Find a related model by its primary key or return new instance of the related model.

public findOrNew(mixed $id[, array<string|int, mixed> $columns = ['*'] ]) : Collection|Model
Parameters
$id : mixed
$columns : array<string|int, mixed> = ['*']
Return values
Collection|Model

first()

Execute the query and get the first result.

public first([array<string|int, mixed> $columns = ['*'] ]) : mixed
Parameters
$columns : array<string|int, mixed> = ['*']
Return values
mixed

firstOrCreate()

Get the first related record matching the attributes or create it.

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

firstOrFail()

Execute the query and get the first result or throw an exception.

public firstOrFail([array<string|int, mixed> $columns = ['*'] ]) : Model|static
Parameters
$columns : array<string|int, mixed> = ['*']
Tags
throws
ModelNotFoundException
Return values
Model|static

firstOrNew()

Get the first related model record matching the attributes or instantiate it.

public firstOrNew(array<string|int, mixed> $attributes) : Model
Parameters
$attributes : array<string|int, mixed>
Return values
Model

get()

Execute the query as a "select" statement.

public get([array<string|int, mixed> $columns = ['*'] ]) : Collection
Parameters
$columns : array<string|int, mixed> = ['*']
Return values
Collection

getBaseQuery()

Get the base query builder driving the Eloquent builder.

public getBaseQuery() : Builder
Return values
Builder

getExistenceCompareKey()

Get the key for comparing against the parent key in "has" query.

public getExistenceCompareKey() : string
Return values
string

getForeignKey()

Get the fully qualified foreign key for the relation.

public getForeignKey() : string
Return values
string

getForeignPivotKeyName()

Get the foreign key for the relation.

public getForeignPivotKeyName() : string
Return values
string

getMorphedModel()

Get the model associated with a custom polymorphic type.

public static getMorphedModel(string $alias) : string|null
Parameters
$alias : string
Return values
string|null

getOtherKey()

Get the fully qualified "other key" for the relation.

public getOtherKey() : string
Return values
string

getParent()

Get the parent model of the relation.

public getParent() : Model
Return values
Model

getPivotAccessor()

Get the name of the pivot accessor for this relationship.

public getPivotAccessor() : string
Return values
string

getQualifiedForeignPivotKeyName()

Get the fully qualified foreign key for the relation.

public getQualifiedForeignPivotKeyName() : string
Return values
string

getQualifiedParentKeyName()

Get the fully qualified parent key name.

public getQualifiedParentKeyName() : string
Return values
string

getQualifiedRelatedPivotKeyName()

Get the fully qualified "related key" for the relation.

public getQualifiedRelatedPivotKeyName() : string
Return values
string

getRelated()

Get the related model of the relation.

public getRelated() : Model
Return values
Model

getRelatedIds()

public getRelatedIds([mixed $sessionKey = null ]) : mixed
Parameters
$sessionKey : mixed = null
Tags
deprecated

Use allRelatedIds instead. Remove if year >= 2018.

Return values
mixed

getRelatedPivotKeyName()

Get the "related key" for the relation.

public getRelatedPivotKeyName() : string
Return values
string

getRelationCountHash()

Get a relationship join table hash.

public getRelationCountHash() : string
Return values
string

getRelationExistenceCountQuery()

Add the constraints for a relationship count query.

public getRelationExistenceCountQuery(Builder $query, Builder $parentQuery) : Builder
Parameters
$query : Builder
$parentQuery : Builder
Return values
Builder

getRelationExistenceQuery()

Add the constraints for an internal relationship existence query.

public getRelationExistenceQuery(Builder $query, Builder $parentQuery[, array<string|int, mixed>|mixed $columns = ['*'] ]) : Builder

Essentially, these queries compare on column names like whereColumn.

Parameters
$query : Builder
$parentQuery : Builder
$columns : array<string|int, mixed>|mixed = ['*']
Return values
Builder

getRelationExistenceQueryForSelfJoin()

Add the constraints for a relationship query on the same table.

public getRelationExistenceQueryForSelfJoin(Builder $query, Builder $parentQuery[, array<string|int, mixed>|mixed $columns = ['*'] ]) : Builder
Parameters
$query : Builder
$parentQuery : Builder
$columns : array<string|int, mixed>|mixed = ['*']
Return values
Builder

getRelationName()

Get the relationship name for the relationship.

public getRelationName() : string
Return values
string

getResults()

Get the results of the relationship.

public abstract getResults() : mixed
Return values
mixed

getSimpleValue()

Helper for getting this relationship simple value, generally useful with form values.

public getSimpleValue() : mixed
Return values
mixed

getTable()

Get the intermediate table for the relationship.

public getTable() : string
Return values
string

hasMacro()

Checks if macro is registered.

public static hasMacro(string $name) : bool
Parameters
$name : string
Return values
bool

initRelation()

Initialize the relation on a set of models.

public abstract initRelation(array<string|int, mixed> $models, string $relation) : array<string|int, mixed>
Parameters
$models : array<string|int, mixed>
$relation : string
Return values
array<string|int, mixed>

macro()

Register a custom macro.

public static macro(string $name, object|callable $macro) : void
Parameters
$name : string
$macro : object|callable
Return values
void

match()

Match the eagerly loaded results to their parents.

public abstract match(array<string|int, mixed> $models, Collection $results, string $relation) : array<string|int, mixed>
Parameters
$models : array<string|int, mixed>
$results : Collection
$relation : string
Return values
array<string|int, mixed>

mixin()

Mix another object into the class.

public static mixin(object $mixin) : void
Parameters
$mixin : object
Return values
void

morphMap()

Set or get the morph map for polymorphic relations.

public static morphMap([array<string|int, mixed>|null $map = null ][, bool $merge = true ]) : array<string|int, mixed>
Parameters
$map : array<string|int, mixed>|null = null
$merge : bool = true
Return values
array<string|int, mixed>

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

noConstraints()

Run a callback with constraints disabled on the relation.

public static noConstraints(Closure $callback) : mixed
Parameters
$callback : Closure
Return values
mixed

orWherePivot()

Set an "or where" clause for a pivot table column.

public orWherePivot(string $column[, string $operator = null ][, mixed $value = null ]) : BelongsToMany
Parameters
$column : string
$operator : string = null
$value : mixed = null
Return values
BelongsToMany

orWherePivotIn()

Set an "or where in" clause for a pivot table column.

public orWherePivotIn(string $column, mixed $values) : BelongsToMany
Parameters
$column : string
$values : mixed
Return values
BelongsToMany

paginate()

Get a paginator for the "select" statement. Complies with October Rain.

public paginate([int $perPage = 15 ][, int $currentPage = null ][, array<string|int, mixed> $columns = ['*'] ][, string $pageName = 'page' ]) : LengthAwarePaginator
Parameters
$perPage : int = 15
$currentPage : int = null
$columns : array<string|int, mixed> = ['*']
$pageName : string = 'page'
Return values
LengthAwarePaginator

rawUpdate()

Run a raw update against the base query.

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

relatedUpdatedAt()

Get the name of the related model's "updated at" column.

public relatedUpdatedAt() : string
Return values
string

remove()

Removes a model from this relationship type.

public remove(Model $model[, mixed $sessionKey = null ]) : mixed
Parameters
$model : Model
$sessionKey : mixed = null
Return values
mixed

save()

Save the supplied related model with deferred binding support.

public save(Model $model[, array<string|int, mixed> $pivotData = [] ][, mixed $sessionKey = null ]) : Model
Parameters
$model : Model
$pivotData : array<string|int, mixed> = []
$sessionKey : mixed = null
Return values
Model

saveMany()

Save an array of new models and attach them to the parent model.

public saveMany(Collection|array<string|int, mixed> $models[, array<string|int, mixed> $pivotAttributes = [] ]) : array<string|int, mixed>
Parameters
$models : Collection|array<string|int, mixed>
$pivotAttributes : array<string|int, mixed> = []
Return values
array<string|int, mixed>

setSimpleValue()

Helper for setting this relationship using various expected values. For example, $model->relation = $value;

public setSimpleValue(mixed $value) : mixed
Parameters
$value : mixed
Return values
mixed

simplePaginate()

Paginate the given query into a simple paginator.

public simplePaginate([int $perPage = null ][, array<string|int, mixed> $columns = ['*'] ][, string $pageName = 'page' ][, int|null $page = null ]) : Paginator
Parameters
$perPage : int = null
$columns : array<string|int, mixed> = ['*']
$pageName : string = 'page'
$page : int|null = null
Return values
Paginator

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>

touch()

Touch all of the related models for the relationship.

public touch() : void
Return values
void

touchIfTouching()

If we're touching the parent model, touch.

public touchIfTouching() : void
Return values
void

updatedAt()

Get the name of the "updated at" column.

public updatedAt() : string
Return values
string

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

updateOrCreate()

Create or update a related record matching the attributes, and fill it with values.

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

wherePivot()

Set a where clause for a pivot table column.

public wherePivot(string $column[, string $operator = null ][, mixed $value = null ][, string $boolean = 'and' ]) : BelongsToMany
Parameters
$column : string
$operator : string = null
$value : mixed = null
$boolean : string = 'and'
Return values
BelongsToMany

wherePivotIn()

Set a "where in" clause for a pivot table column.

public wherePivotIn(string $column, mixed $values[, string $boolean = 'and' ][, bool $not = false ]) : BelongsToMany
Parameters
$column : string
$values : mixed
$boolean : string = 'and'
$not : bool = false
Return values
BelongsToMany

withDeferred()

Returns the model query with deferred bindings added

public withDeferred(mixed $sessionKey) : Builder
Parameters
$sessionKey : mixed
Return values
Builder

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

withTimestamps()

Specify that the pivot table has creation and update timestamps.

public withTimestamps([mixed $createdAt = null ][, mixed $updatedAt = null ]) : BelongsToMany
Parameters
$createdAt : mixed = null
$updatedAt : mixed = null
Return values
BelongsToMany

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>

addWhereConstraints()

Set the where clause for the relation query.

protected addWhereConstraints() : $this
Return values
$this

aliasedPivotColumns()

Get the pivot columns for the relation.

protected aliasedPivotColumns() : array<string|int, mixed>

"pivot_" is prefixed ot each column for easy removal later.

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>

buildDictionary()

Build model dictionary keyed by the relation's foreign key.

protected buildDictionary(Collection $results) : array<string|int, mixed>
Parameters
$results : Collection
Return values
array<string|int, mixed>

buildMorphMapFromModels()

Builds a table-keyed array from model class names.

protected static buildMorphMapFromModels([array<string|int, string>|null $models = null ]) : array<string|int, mixed>|null
Parameters
$models : array<string|int, string>|null = null
Return values
array<string|int, mixed>|null

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>

getKeys()

Get all of the primary keys for an array of models.

protected getKeys(array<string|int, mixed> $models[, string $key = null ]) : array<string|int, mixed>
Parameters
$models : array<string|int, mixed>
$key : string = null
Return values
array<string|int, mixed>

getWithDeferredQualifiedKeyName()

Returns the related "slave id" key in a database friendly format.

protected getWithDeferredQualifiedKeyName() : Expression
Return values
Expression

guessInverseRelation()

Attempt to guess the name of the inverse of the relation.

protected guessInverseRelation() : string
Return values
string

hasPivotColumn()

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

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

hydratePivotRelation()

Hydrate the pivot table relationship on the models.

protected hydratePivotRelation(array<string|int, mixed> $models) : void
Parameters
$models : array<string|int, mixed>
Return values
void

migratePivotAttributes()

Get the pivot attributes from a model.

protected migratePivotAttributes(Model $model) : array<string|int, mixed>
Parameters
$model : Model
Return values
array<string|int, mixed>

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>

performJoin()

Set the join clause for the relation query.

protected performJoin([Builder|null $query = null ]) : $this
Parameters
$query : Builder|null = null
Return values
$this

shouldSelect()

Get the select columns for the relation query.

protected shouldSelect([array<string|int, mixed> $columns = ['*'] ]) : BelongsToMany
Parameters
$columns : array<string|int, mixed> = ['*']
Return values
BelongsToMany

touchingParent()

Determine if we should touch the parent on sync.

protected touchingParent() : bool
Return values
bool

Search results