class MorphToMany extends BelongsToMany (View source)

Methods

void
__construct( Builder $query, Model $parent, string $name, string $table, string $foreignKey, string $otherKey, string $relationName = null, bool $inverse = false)

Create a new morph to many relationship instance.

void
addConstraints()

Set the base constraints on the relation query.

void
addEagerConstraints( array $models)

Set the constraints for an eager load of the relation.

array
initRelation( array $models, string $relation)

Initialize the relation on a set of models.

array
match( array $models, Collection $results, string $relation)

Match the eagerly loaded results to their parents.

mixed
getResults()

Get the results of the relationship.

getEager()

Get the relationship for eager loading.

from Relation
void
touch()

Touch all of the related models for the relationship.

int
rawUpdate( array $attributes = array())

Run a raw update against the base query.

from Relation
getRelationCountQuery( Builder $query, Builder $parent)

Add the constraints for a relationship count query.

from Relation
getRelationQuery( Builder $query, Builder $parent, array|mixed $columns = array('*'))

Add the constraints for a relationship count query.

static  mixed
noConstraints( Closure $callback)

Run a callback with constraints disabled on the relation.

from Relation
getQuery()

Get the underlying query for the relation.

from Relation
getBaseQuery()

Get the base query builder driving the Eloquent builder.

from Relation
getParent()

Get the parent model of the relation.

from Relation
string
getQualifiedParentKeyName()

Get the fully qualified parent key name.

from Relation
getRelated()

Get the related model of the relation.

from Relation
string
createdAt()

Get the name of the "created at" column.

string
updatedAt()

Get the name of the "updated at" column.

string
relatedUpdatedAt()

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

from Relation
string
wrap( string $value)

Wrap the given value with the parent query's grammar.

from Relation
static  array
morphMap( array $map = null, bool $merge = true)

Set or get the morph map for polymorphic relations.

from Relation
mixed
__call( string $method, array $parameters)

Handle dynamic method calls to the relationship.

from Relation
void
__clone()

Force a clone of the underlying query builder when cloning.

from Relation
wherePivot( string $column, string $operator = null, mixed $value = null, string $boolean = 'and')

Set a where clause for a pivot table column.

wherePivotIn( string $column, mixed $values, string $boolean = 'and', bool $not = false)

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

orWherePivot( string $column, string $operator = null, mixed $value = null)

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

orWherePivotIn( string $column, mixed $values)

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

mixed
first( array $columns = array('*'))

Execute the query and get the first result.

firstOrFail( array $columns = array('*'))

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

get( array $columns = array('*'))

Execute the query as a "select" statement.

paginate( int $perPage = null, array $columns = array('*'), string $pageName = 'page', int|null $page = null)

Get a paginator for the "select" statement.

simplePaginate( int $perPage = null, array $columns = array('*'), string $pageName = 'page')

Paginate the given query into a simple paginator.

bool
chunk( int $count, callable $callback)

Chunk the results of the query.

getRelationQueryForSelfJoin( Builder $query, Builder $parent, array|mixed $columns = array('*'))

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

string
getRelationCountHash()

Get a relationship join table hash.

getRelatedIds()

Get all of the IDs for the related models.

save( Model $model, array $joining = array(), bool $touch = true)

Save a new model and attach it to the parent model.

array
saveMany( Collection|array $models, array $joinings = array())

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

find( mixed $id, array $columns = array('*'))

Find a related model by its primary key.

findMany( mixed $ids, array $columns = array('*'))

Find multiple related models by their primary keys.

findOrFail( mixed $id, array $columns = array('*'))

Find a related model by its primary key or throw an exception.

findOrNew( mixed $id, array $columns = array('*'))

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

firstOrNew( array $attributes)

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

firstOrCreate( array $attributes, array $joining = array(), bool $touch = true)

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

updateOrCreate( array $attributes, array $values = array(), array $joining = array(), bool $touch = true)

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

create( array $attributes, array $joining = array(), bool $touch = true)

Create a new instance of the related model.

array
createMany( array $records, array $joinings = array())

Create an array of new instances of the related models.

array
sync( 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( int|array $ids = array(), bool $touch = true)

Detach models from the relationship.

void
touchIfTouching()

If we're touching the parent model, touch.

newPivotStatement()

Get a new plain query builder for the pivot table.

newPivotStatementForId( mixed $id)

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

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

Create a new pivot model instance.

newExistingPivot( array $attributes = array())

Create a new existing pivot model instance.

$this
withPivot( array|mixed $columns)

Set the columns on the pivot table to retrieve.

withTimestamps( mixed $createdAt = null, mixed $updatedAt = null)

Specify that the pivot table has creation and update timestamps.

string
getRelatedFreshUpdate()

Get the related model's updated at column name.

string
getHasCompareKey()

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

string
getForeignKey()

Get the fully qualified foreign key for the relation.

string
getOtherKey()

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

string
getTable()

Get the intermediate table for the relationship.

string
getRelationName()

Get the relationship name for the relationship.

string
getMorphType()

Get the foreign key "type" name.

string
getMorphClass()

Get the class name of the parent model.

Details

at line line 47
void __construct( Builder $query, Model $parent, string $name, string $table, string $foreignKey, string $otherKey, string $relationName = null, bool $inverse = false)

Create a new morph to many relationship instance.

Parameters

Builder $query
Model $parent
string $name
string $table
string $foreignKey
string $otherKey
string $relationName
bool $inverse

Return Value

void

void addConstraints()

Set the base constraints on the relation query.

Return Value

void

at line line 91
void addEagerConstraints( array $models)

Set the constraints for an eager load of the relation.

Parameters

array $models

Return Value

void

array initRelation( array $models, string $relation)

Initialize the relation on a set of models.

Parameters

array $models
string $relation

Return Value

array

array match( array $models, Collection $results, string $relation)

Match the eagerly loaded results to their parents.

Parameters

array $models
Collection $results
string $relation

Return Value

array

mixed getResults()

Get the results of the relationship.

Return Value

mixed

in Relation at line line 111
Collection getEager()

Get the relationship for eager loading.

Return Value

Collection

void touch()

Touch all of the related models for the relationship.

E.g.: Touch all roles associated with this user.

Return Value

void

in Relation at line line 134
int rawUpdate( array $attributes = array())

Run a raw update against the base query.

Parameters

array $attributes

Return Value

int

in Relation at line line 146
Builder getRelationCountQuery( Builder $query, Builder $parent)

Add the constraints for a relationship count query.

Parameters

Builder $query
Builder $parent

Return Value

Builder

at line line 78
Builder getRelationQuery( Builder $query, Builder $parent, array|mixed $columns = array('*'))

Add the constraints for a relationship count query.

Parameters

Builder $query
Builder $parent
array|mixed $columns

Return Value

Builder

in Relation at line line 174
static mixed noConstraints( Closure $callback)

Run a callback with constraints disabled on the relation.

Parameters

Closure $callback

Return Value

mixed

in Relation at line line 212
Builder getQuery()

Get the underlying query for the relation.

Return Value

Builder

in Relation at line line 222
Builder getBaseQuery()

Get the base query builder driving the Eloquent builder.

Return Value

Builder

in Relation at line line 232
Model getParent()

Get the parent model of the relation.

Return Value

Model

in Relation at line line 242
string getQualifiedParentKeyName()

Get the fully qualified parent key name.

Return Value

string

in Relation at line line 252
Model getRelated()

Get the related model of the relation.

Return Value

Model

string createdAt()

Get the name of the "created at" column.

Return Value

string

string updatedAt()

Get the name of the "updated at" column.

Return Value

string

in Relation at line line 282
string relatedUpdatedAt()

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

Return Value

string

in Relation at line line 293
string wrap( string $value)

Wrap the given value with the parent query's grammar.

Parameters

string $value

Return Value

string

in Relation at line line 305
static array morphMap( array $map = null, bool $merge = true)

Set or get the morph map for polymorphic relations.

Parameters

array $map
bool $merge

Return Value

array

in Relation at line line 342
mixed __call( string $method, array $parameters)

Handle dynamic method calls to the relationship.

Parameters

string $method
array $parameters

Return Value

mixed

in Relation at line line 358
void __clone()

Force a clone of the underlying query builder when cloning.

Return Value

void

BelongsToMany wherePivot( string $column, string $operator = null, mixed $value = null, string $boolean = 'and')

Set a where clause for a pivot table column.

Parameters

string $column
string $operator
mixed $value
string $boolean

Return Value

BelongsToMany

BelongsToMany wherePivotIn( string $column, mixed $values, string $boolean = 'and', bool $not = false)

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

Parameters

string $column
mixed $values
string $boolean
bool $not

Return Value

BelongsToMany

BelongsToMany orWherePivot( string $column, string $operator = null, mixed $value = null)

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

Parameters

string $column
string $operator
mixed $value

Return Value

BelongsToMany

BelongsToMany orWherePivotIn( string $column, mixed $values)

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

Parameters

string $column
mixed $values

Return Value

BelongsToMany

mixed first( array $columns = array('*'))

Execute the query and get the first result.

Parameters

array $columns

Return Value

mixed

Model|BelongsToMany firstOrFail( array $columns = array('*'))

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

Parameters

array $columns

Return Value

Model|BelongsToMany

Exceptions

ModelNotFoundException

Collection get( array $columns = array('*'))

Execute the query as a "select" statement.

Parameters

array $columns

Return Value

Collection

LengthAwarePaginator paginate( int $perPage = null, array $columns = array('*'), string $pageName = 'page', int|null $page = null)

Get a paginator for the "select" statement.

Parameters

int $perPage
array $columns
string $pageName
int|null $page

Return Value

LengthAwarePaginator

Paginator simplePaginate( int $perPage = null, array $columns = array('*'), string $pageName = 'page')

Paginate the given query into a simple paginator.

Parameters

int $perPage
array $columns
string $pageName

Return Value

Paginator

bool chunk( int $count, callable $callback)

Chunk the results of the query.

Parameters

int $count
callable $callback

Return Value

bool

Builder getRelationQueryForSelfJoin( Builder $query, Builder $parent, array|mixed $columns = array('*'))

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

Parameters

Builder $query
Builder $parent
array|mixed $columns

Return Value

Builder

string getRelationCountHash()

Get a relationship join table hash.

Return Value

string

Collection getRelatedIds()

Get all of the IDs for the related models.

Return Value

Collection

Model save( Model $model, array $joining = array(), bool $touch = true)

Save a new model and attach it to the parent model.

Parameters

Model $model
array $joining
bool $touch

Return Value

Model

array saveMany( Collection|array $models, array $joinings = array())

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

Parameters

Collection|array $models
array $joinings

Return Value

array

Model|Collection|null find( mixed $id, array $columns = array('*'))

Find a related model by its primary key.

Parameters

mixed $id
array $columns

Return Value

Model|Collection|null

Collection findMany( mixed $ids, array $columns = array('*'))

Find multiple related models by their primary keys.

Parameters

mixed $ids
array $columns

Return Value

Collection

Model|Collection findOrFail( mixed $id, array $columns = array('*'))

Find a related model by its primary key or throw an exception.

Parameters

mixed $id
array $columns

Return Value

Model|Collection

Exceptions

ModelNotFoundException

Collection|Model findOrNew( mixed $id, array $columns = array('*'))

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

Parameters

mixed $id
array $columns

Return Value

Collection|Model

Model firstOrNew( array $attributes)

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

Parameters

array $attributes

Return Value

Model

Model firstOrCreate( array $attributes, array $joining = array(), bool $touch = true)

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

Parameters

array $attributes
array $joining
bool $touch

Return Value

Model

Model updateOrCreate( array $attributes, array $values = array(), array $joining = array(), bool $touch = true)

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

Parameters

array $attributes
array $values
array $joining
bool $touch

Return Value

Model

Model create( array $attributes, array $joining = array(), bool $touch = true)

Create a new instance of the related model.

Parameters

array $attributes
array $joining
bool $touch

Return Value

Model

array createMany( array $records, array $joinings = array())

Create an array of new instances of the related models.

Parameters

array $records
array $joinings

Return Value

array

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

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

Parameters

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( int|array $ids = array(), bool $touch = true)

Detach models from the relationship.

Parameters

int|array $ids
bool $touch

Return Value

int

void touchIfTouching()

If we're touching the parent model, touch.

Return Value

void

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

at line line 131
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

$this withPivot( array|mixed $columns)

Set the columns on the pivot table to retrieve.

Parameters

array|mixed $columns

Return Value

$this

BelongsToMany withTimestamps( mixed $createdAt = null, mixed $updatedAt = null)

Specify that the pivot table has creation and update timestamps.

Parameters

mixed $createdAt
mixed $updatedAt

Return Value

BelongsToMany

string getRelatedFreshUpdate()

Get the related model's updated at column name.

Return Value

string

string getHasCompareKey()

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

Return Value

string

string getForeignKey()

Get the fully qualified foreign key for the relation.

Return Value

string

string getOtherKey()

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

Return Value

string

string getTable()

Get the intermediate table for the relationship.

Return Value

string

string getRelationName()

Get the relationship name for the relationship.

Return Value

string

at line line 147
string getMorphType()

Get the foreign key "type" name.

Return Value

string

at line line 157
string getMorphClass()

Get the class name of the parent model.

Return Value

string