class Illuminate / Database / Eloquent / Relations / HasManyThrough
You are viewing an older version of the documentation. For the latest, please visit master documentation.

HasManyThrough

Extends

Uses

Properties

protected

$throughParent Model

The "through" parent model instance.

Default: null
protected

$farParent Model

The far parent model instance.

Default: null
protected

$firstKey string

The near key on the relationship.

Default: null
protected

$secondKey string

The far key on the relationship.

Default: null
protected

$localKey string

The local key on the relationship.

Default: null
protected

$secondLocalKey string

The local key on the intermediary model.

Default: null

Methods

public

__construct ( Builder $query , Model $farParent , Model $throughParent , $firstKey , $secondKey , $localKey , $secondLocalKey ) : void

Create a new has many through relationship instance.

Parameters

  • $query Builder
  • $farParent Model
  • $throughParent Model
  • $firstKey string
  • $secondKey string
  • $localKey string
  • $secondLocalKey string
public

addConstraints ( ) : void

Set the base constraints on the relation query.

protected

performJoin ( Builder $query ) : void

Set the join clause on the query.

Parameters

public

getQualifiedParentKeyName ( ) : string

Get the fully qualified parent key name.

public

throughParentSoftDeletes ( ) : bool

Determine whether "through" parent of the relation uses Soft Deletes.

public

withTrashedParents ( ) : $this

Indicate that trashed "through" parents should be included in the query.

public

addEagerConstraints ( array $models ) : void

Set the constraints for an eager load of the relation.

Parameters

  • $models array
public

initRelation ( array $models , $relation ) : array

Initialize the relation on a set of models.

Parameters

  • $models array
  • $relation string
public

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

Match the eagerly loaded results to their parents.

Parameters

protected

buildDictionary ( Collection $results ) : array

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

Parameters

public

firstOrNew ( array $attributes ) : Model

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

Parameters

  • $attributes array
public

updateOrCreate ( array $attributes , array $values ) : Model

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

Parameters

  • $attributes array
  • $values array
public

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
public

first ( $columns ) : mixed

Execute the query and get the first related model.

Parameters

  • $columns array
public

firstOrFail ( $columns ) : Model |static

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

Parameters

  • $columns array
public

find ( $id , $columns ) : Model |Collection |null

Find a related model by its primary key.

Parameters

  • $id mixed
  • $columns array
public

findMany ( $ids , $columns ) : Collection

Find multiple related models by their primary keys.

Parameters

public

findOrFail ( $id , $columns ) : Model |Collection

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

Parameters

  • $id mixed
  • $columns array
public

getResults ( ) : mixed

Get the results of the relationship.

public

get ( $columns ) : Collection

Execute the query as a "select" statement.

Parameters

  • $columns array
public

paginate ( $perPage , $columns , $pageName , $page ) : LengthAwarePaginator

Get a paginator for the "select" statement.

Parameters

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

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
public

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
protected

shouldSelect ( array $columns ) : array

Set the select clause for the relation query.

Parameters

  • $columns array
public

chunk ( $count , callable $callback ) : bool

Chunk the results of the query.

Parameters

  • $count int
  • $callback callable
public

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
public

cursor ( ) : Generator

Get a generator for the given query.

public

each ( callable $callback , $count ) : bool

Execute a callback over each item while chunking.

Parameters

  • $callback callable
  • $count int
public

lazy ( $chunkSize ) : LazyCollection

Query lazily, by chunks of the given size.

Parameters

  • $chunkSize int
public

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
protected

prepareQueryBuilder ( $columns ) : Builder

Prepare the query builder for query execution.

Parameters

  • $columns array
public

getRelationExistenceQuery ( Builder $query , Builder $parentQuery , $columns ) : Builder

Add the constraints for a relationship query.

Parameters

public

getRelationExistenceQueryForSelfRelation ( Builder $query , Builder $parentQuery , $columns ) : Builder

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

Parameters

public

getRelationExistenceQueryForThroughSelfRelation ( Builder $query , Builder $parentQuery , $columns ) : Builder

Add the constraints for a relationship query on the same table as the through parent.

Parameters

public

getQualifiedFarKeyName ( ) : string

Get the qualified foreign key on the related model.

public

getFirstKeyName ( ) : string

Get the foreign key on the "through" model.

public

getQualifiedFirstKeyName ( ) : string

Get the qualified foreign key on the "through" model.

public

getForeignKeyName ( ) : string

Get the foreign key on the related model.

public

getQualifiedForeignKeyName ( ) : string

Get the qualified foreign key on the related model.

public

getLocalKeyName ( ) : string

Get the local key on the far parent model.

public

getQualifiedLocalKeyName ( ) : string

Get the qualified local key on the far parent model.

public

getSecondLocalKeyName ( ) : string

Get the local key on the intermediary model.