BelongsToMany
Extends
Uses
Properties
$table string
The intermediate table for the relation.
$foreignPivotKey string
The foreign key of the parent model.
$relatedPivotKey string
The associated key of the relation.
$parentKey string
The key name of the parent model.
$relatedKey string
The key name of the related model.
$relationName string
The "name" of the relationship.
$pivotColumns array
The pivot table columns to retrieve.
$pivotWheres array
Any pivot table restrictions for where clauses.
$pivotWhereIns array
Any pivot table restrictions for whereIn clauses.
$pivotWhereNulls array
Any pivot table restrictions for whereNull clauses.
$pivotValues array
The default values for the pivot columns.
$withTimestamps bool
Indicates if timestamps are available on the pivot table.
$pivotCreatedAt string
The custom pivot table column for the created_at timestamp.
$pivotUpdatedAt string
The custom pivot table column for the updated_at timestamp.
$using string
The class name of the custom pivot model to use for the relationship.
$accessor string
The name of the accessor to use for the "pivot" relationship.
Methods
__construct ( Builder $query , Model $parent , $table , $foreignPivotKey , $relatedPivotKey , $parentKey , $relatedKey , $relationName ) : void
Create a new belongs to many relationship instance.
Parameters
resolveTableName ( $table ) : string
Attempt to resolve the intermediate table name from the given string.
Parameters
- $table string
addConstraints ( ) : void
Set the base constraints on the relation query.
performJoin ( $query ) : $this
Set the join clause for the relation query.
Parameters
- $query Builder |null
addWhereConstraints ( ) : $this
Set the where clause for the relation query.
addEagerConstraints ( array $models ) : void
Set the constraints for an eager load of the relation.
Parameters
- $models array
initRelation ( array $models , $relation ) : array
Initialize the relation on a set of models.
Parameters
- $models array
- $relation string
match ( array $models , Collection $results , $relation ) : array
Match the eagerly loaded results to their parents.
Parameters
- $models array
- $results Collection
- $relation string
buildDictionary ( Collection $results ) : array
Build model dictionary keyed by the relation's foreign key.
Parameters
- $results Collection
getPivotClass ( ) : string
Get the class being used for pivot models.
using ( $class ) : $this
Specify the custom pivot model to use for the relationship.
Parameters
- $class string
as ( $accessor ) : $this
Specify the custom pivot accessor to use for the relationship.
Parameters
- $accessor string
wherePivot ( $column , $operator , $value , $boolean ) : $this
Set a where clause for a pivot table column.
Parameters
- $column string
- $operator mixed
- $value mixed
- $boolean string
wherePivotBetween ( $column , array $values , $boolean , $not ) : $this
Set a "where between" clause for a pivot table column.
Parameters
- $column string
- $values array
- $boolean string
- $not bool
orWherePivotBetween ( $column , array $values ) : $this
Set a "or where between" clause for a pivot table column.
Parameters
- $column string
- $values array
wherePivotNotBetween ( $column , array $values , $boolean ) : $this
Set a "where pivot not between" clause for a pivot table column.
Parameters
- $column string
- $values array
- $boolean string
orWherePivotNotBetween ( $column , array $values ) : $this
Set a "or where not between" clause for a pivot table column.
Parameters
- $column string
- $values array
wherePivotIn ( $column , $values , $boolean , $not ) : $this
Set a "where in" clause for a pivot table column.
Parameters
- $column string
- $values mixed
- $boolean string
- $not bool
orWherePivot ( $column , $operator , $value ) : $this
Set an "or where" clause for a pivot table column.
Parameters
- $column string
- $operator mixed
- $value mixed
withPivotValue ( $column , $value ) : $this
Set a where clause for a pivot table column.
Parameters
- $column string|array
- $value mixed
orWherePivotIn ( $column , $values ) : $this
Set an "or where in" clause for a pivot table column.
Parameters
- $column string
- $values mixed
wherePivotNotIn ( $column , $values , $boolean ) : $this
Set a "where not in" clause for a pivot table column.
Parameters
- $column string
- $values mixed
- $boolean string
orWherePivotNotIn ( $column , $values ) : $this
Set an "or where not in" clause for a pivot table column.
Parameters
- $column string
- $values mixed
wherePivotNull ( $column , $boolean , $not ) : $this
Set a "where null" clause for a pivot table column.
Parameters
- $column string
- $boolean string
- $not bool
wherePivotNotNull ( $column , $boolean ) : $this
Set a "where not null" clause for a pivot table column.
Parameters
- $column string
- $boolean string
orWherePivotNull ( $column , $not ) : $this
Set a "or where null" clause for a pivot table column.
Parameters
- $column string
- $not bool
orWherePivotNotNull ( $column ) : $this
Set a "or where not null" clause for a pivot table column.
Parameters
- $column string
orderByPivot ( $column , $direction ) : $this
Add an "order by" clause for a pivot table column.
Parameters
- $column string
- $direction string
findOrNew ( $id , $columns ) : Collection |Model
Find a related model by its primary key or return a new instance of the related model.
Parameters
- $id mixed
- $columns array
firstOrNew ( array $attributes ) : Model
Get the first related model record matching the attributes or instantiate it.
Parameters
- $attributes array
firstOrCreate ( array $attributes , array $joining , $touch ) : Model
Get the first related record matching the attributes or create it.
Parameters
- $attributes array
- $joining array
- $touch bool
updateOrCreate ( array $attributes , array $values , array $joining , $touch ) : Model
Create or update a related record matching the attributes, and fill it with values.
Parameters
- $attributes array
- $values array
- $joining array
- $touch bool
find ( $id , $columns ) : Model |Collection |null
Find a related model by its primary key.
Parameters
- $id mixed
- $columns array
findMany ( $ids , $columns ) : Collection
Find multiple related models by their primary keys.
Parameters
- $ids Arrayable |array
- $columns array
findOrFail ( $id , $columns ) : Model |Collection
Find a related model by its primary key or throw an exception.
Parameters
- $id mixed
- $columns array
firstWhere ( $column , $operator , $value , $boolean ) : Model |static
Add a basic where clause to the query, and return the first result.
Parameters
- $column Closure |string|array
- $operator mixed
- $value mixed
- $boolean string
first ( $columns ) : mixed
Execute the query and get the first result.
Parameters
- $columns array
firstOrFail ( $columns ) : Model |static
Execute the query and get the first result or throw an exception.
Parameters
- $columns array
firstOr ( $columns , Closure $callback ) : Model |static|mixed
Execute the query and get the first result or call a callback.
Parameters
getResults ( ) : mixed
Get the results of the relationship.
get ( $columns ) : Collection
Execute the query as a "select" statement.
Parameters
- $columns array
shouldSelect ( array $columns ) : array
Get the select columns for the relation query.
Parameters
- $columns array
aliasedPivotColumns ( ) : array
Get the pivot columns for the relation.
paginate ( $perPage , $columns , $pageName , $page ) : LengthAwarePaginator
Get a paginator for the "select" statement.
Parameters
- $perPage int|null
- $columns array
- $pageName string
- $page int|null
simplePaginate ( $perPage , $columns , $pageName , $page ) : Paginator
Paginate the given query into a simple paginator.
Parameters
- $perPage int|null
- $columns array
- $pageName string
- $page int|null
cursorPaginate ( $perPage , $columns , $cursorName , $cursor ) : CursorPaginator
Paginate the given query into a cursor paginator.
Parameters
- $perPage int|null
- $columns array
- $cursorName string
- $cursor string|null
chunk ( $count , callable $callback ) : bool
Chunk the results of the query.
Parameters
- $count int
- $callback callable
chunkById ( $count , callable $callback , $column , $alias ) : bool
Chunk the results of a query by comparing numeric IDs.
Parameters
- $count int
- $callback callable
- $column string|null
- $alias string|null
each ( callable $callback , $count ) : bool
Execute a callback over each item while chunking.
Parameters
- $callback callable
- $count int
lazy ( $chunkSize ) : LazyCollection
Query lazily, by chunks of the given size.
Parameters
- $chunkSize int
lazyById ( $chunkSize , $column , $alias ) : LazyCollection
Query lazily, by chunking the results of a query by comparing IDs.
Parameters
- $chunkSize int
- $column string|null
- $alias string|null
hydratePivotRelation ( array $models ) : void
Hydrate the pivot table relationship on the models.
Parameters
- $models array
migratePivotAttributes ( Model $model ) : array
Get the pivot attributes from a model.
Parameters
- $model Model
touchIfTouching ( ) : void
If we're touching the parent model, touch.
touchingParent ( ) : bool
Determine if we should touch the parent on sync.
guessInverseRelation ( ) : string
Attempt to guess the name of the inverse of the relation.
touch ( ) : void
Touch all of the related models for the relationship.
save ( Model $model , array $pivotAttributes , $touch ) : Model
Save a new model and attach it to the parent model.
Parameters
- $model Model
- $pivotAttributes array
- $touch bool
saveMany ( $models , array $pivotAttributes ) : array
Save an array of new models and attach them to the parent model.
Parameters
- $models Collection |array
- $pivotAttributes array
create ( array $attributes , array $joining , $touch ) : Model
Create a new instance of the related model.
Parameters
- $attributes array
- $joining array
- $touch bool
createMany ( iterable $records , array $joinings ) : array
Create an array of new instances of the related models.
Parameters
- $records iterable
- $joinings array
getRelationExistenceQuery ( Builder $query , Builder $parentQuery , $columns ) : Builder
Add the constraints for a relationship query.
Parameters
getRelationExistenceQueryForSelfJoin ( Builder $query , Builder $parentQuery , $columns ) : Builder
Add the constraints for a relationship query on the same table.
Parameters
getExistenceCompareKey ( ) : string
Get the key for comparing against the parent key in "has" query.
withTimestamps ( $createdAt , $updatedAt ) : $this
Specify that the pivot table has creation and update timestamps.
Parameters
- $createdAt mixed
- $updatedAt mixed
createdAt ( ) : string
Get the name of the "created at" column.
updatedAt ( ) : string
Get the name of the "updated at" column.
getForeignPivotKeyName ( ) : string
Get the foreign key for the relation.
getQualifiedForeignPivotKeyName ( ) : string
Get the fully qualified foreign key for the relation.
getRelatedPivotKeyName ( ) : string
Get the "related key" for the relation.
getQualifiedRelatedPivotKeyName ( ) : string
Get the fully qualified "related key" for the relation.
getParentKeyName ( ) : string
Get the parent key for the relationship.
getQualifiedParentKeyName ( ) : string
Get the fully qualified parent key name for the relation.
getRelatedKeyName ( ) : string
Get the related key for the relationship.
getQualifiedRelatedKeyName ( ) : string
Get the fully qualified related key name for the relation.
getTable ( ) : string
Get the intermediate table for the relationship.
getRelationName ( ) : string
Get the relationship name for the relationship.
getPivotAccessor ( ) : string
Get the name of the pivot accessor for this relationship.
getPivotColumns ( ) : array
Get the pivot columns for this relationship.
qualifyPivotColumn ( $column ) : string
Qualify the given column name by the pivot table.
Parameters
- $column string