Methods |
public
|
__construct(
Builder<TRelatedModel> $query,
TDeclaringModel $farParent,
TIntermediateModel $throughParent,
string $firstKey,
string $secondKey,
string $localKey,
string $secondLocalKey,
): void
Create a new has many through relationship instance.
Create a new has many through relationship instance.
Overrides
|
#
|
public
|
addConstraints(): void
Set the base constraints on the relation query.
Set the base constraints on the relation query.
Implements
|
#
|
protected
|
performJoin(Builder<TRelatedModel>|null $query = null): void
Set the join clause on the query.
Set the join clause on the query.
|
#
|
public
|
getQualifiedParentKeyName(): string
Get the fully qualified parent key name.
Get the fully qualified parent key name.
Overrides
|
#
|
public
|
throughParentSoftDeletes(): bool
Determine whether "through" parent of the relation uses Soft Deletes.
Determine whether "through" parent of the relation uses Soft Deletes.
|
#
|
public
|
withTrashedParents(): $this
Indicate that trashed "through" parents should be included in the query.
Indicate that trashed "through" parents should be included in the query.
|
#
|
public
|
addEagerConstraints(array $models)
Set the constraints for an eager load of the relation.
Set the constraints for an eager load of the relation.
Implements
|
#
|
protected
|
buildDictionary(Collection<int, TRelatedModel> $results): array<array<TRelatedModel>>
Build model dictionary keyed by the relation's foreign key.
Build model dictionary keyed by the relation's foreign key.
|
#
|
public
|
firstOrNew(array $attributes = [], array $values = []): TRelatedModel
Get the first related model record matching the attributes or instantiate it.
Get the first related model record matching the attributes or instantiate it.
|
#
|
public
|
firstOrCreate(array $attributes = [], array $values = []): TRelatedModel
Get the first record matching the attributes. If the record is not found, create it.
Get the first record matching the attributes. If the record is not found, create it.
|
#
|
public
|
createOrFirst(array $attributes = [], array $values = []): TRelatedModel
Attempt to create the record. If a unique constraint violation occurs, attempt to find the matching record.
Attempt to create the record. If a unique constraint violation occurs, attempt to find the matching record.
|
#
|
public
|
updateOrCreate(array $attributes, array $values = []): TRelatedModel
Create or update a related record matching the attributes, and fill it with values.
Create or update a related record matching the attributes, and fill it with values.
|
#
|
public
|
firstWhere(
Closure|string|array $column,
mixed $operator = null,
mixed $value = null,
string $boolean = 'and',
): TRelatedModel|null
Add a basic where clause to the query, and return the first result.
Add a basic where clause to the query, and return the first result.
|
#
|
public
|
first(array $columns = ['*']): TRelatedModel|null
Execute the query and get the first related model.
Execute the query and get the first related model.
|
#
|
public
|
firstOrFail(array $columns = ['*']): TRelatedModel
Execute the query and get the first result or throw an exception.
Execute the query and get the first result or throw an exception.
Throws
|
#
|
public
|
firstOr<TValue>(
(Closure(): TValue)|list<string> $columns = ['*'],
(Closure(): TValue)|null $callback = null,
): TRelatedModel|TValue
Execute the query and get the first result or call a callback.
Execute the query and get the first result or call a callback.
|
#
|
public
|
find(
mixed $id,
array $columns = ['*'],
): ($id is Arrayable<array-key, mixed>|array<mixed> ? Collection<int, TRelatedModel> : TRelatedModel|null)
Find a related model by its primary key.
Find a related model by its primary key.
|
#
|
public
|
findSole(mixed $id, array $columns = ['*']): TRelatedModel
Find a sole related model by its primary key.
Find a sole related model by its primary key.
Throws
|
#
|
public
|
findMany(Arrayable|array $ids, array $columns = ['*']): Collection<int, TRelatedModel>
Find multiple related models by their primary keys.
Find multiple related models by their primary keys.
|
#
|
public
|
findOrFail(
mixed $id,
array $columns = ['*'],
): ($id is Arrayable<array-key, mixed>|array<mixed> ? Collection<int, TRelatedModel> : TRelatedModel)
Find a related model by its primary key or throw an exception.
Find a related model by its primary key or throw an exception.
Throws
|
#
|
public
|
findOr<TValue>(
mixed $id,
(Closure(): TValue)|list<string>|string $columns = ['*'],
(Closure(): TValue)|null $callback = null,
): ($id is Arrayable<array-key, mixed>|array<mixed> ? Collection<int, TRelatedModel>|TValue : TRelatedModel|TValue)
Find a related model by its primary key or call a callback.
Find a related model by its primary key or call a callback.
|
#
|
public
|
get($columns = ['*'])
Execute the query as a "select" statement.
Execute the query as a "select" statement.
Overrides
|
#
|
public
|
paginate(
int|null $perPage = null,
array $columns = ['*'],
string $pageName = 'page',
int $page = null,
): LengthAwarePaginator
Get a paginator for the "select" statement.
Get a paginator for the "select" statement.
|
#
|
public
|
simplePaginate(
int|null $perPage = null,
array $columns = ['*'],
string $pageName = 'page',
int|null $page = null,
): Paginator
Paginate the given query into a simple paginator.
Paginate the given query into a simple paginator.
|
#
|
public
|
cursorPaginate(
int|null $perPage = null,
array $columns = ['*'],
string $cursorName = 'cursor',
string|null $cursor = null,
): CursorPaginator
Paginate the given query into a cursor paginator.
Paginate the given query into a cursor paginator.
|
#
|
protected
|
shouldSelect(array $columns = ['*']): array
Set the select clause for the relation query.
Set the select clause for the relation query.
|
#
|
public
|
chunk(int $count, callable $callback): bool
Chunk the results of the query.
Chunk the results of the query.
|
#
|
public
|
chunkById(int $count, callable $callback, string|null $column = null, string|null $alias = null): bool
Chunk the results of a query by comparing numeric IDs.
Chunk the results of a query by comparing numeric IDs.
|
#
|
public
|
chunkByIdDesc(int $count, callable $callback, string|null $column = null, string|null $alias = null): bool
Chunk the results of a query by comparing IDs in descending order.
Chunk the results of a query by comparing IDs in descending order.
|
#
|
public
|
eachById(callable $callback, int $count = 1000, string|null $column = null, string|null $alias = null): bool
Execute a callback over each item while chunking by ID.
Execute a callback over each item while chunking by ID.
|
#
|
public
|
cursor(): LazyCollection<int, TRelatedModel>
Get a generator for the given query.
Get a generator for the given query.
|
#
|
public
|
each(callable $callback, int $count = 1000): bool
Execute a callback over each item while chunking.
Execute a callback over each item while chunking.
|
#
|
public
|
lazy(int $chunkSize = 1000): LazyCollection<int, TRelatedModel>
Query lazily, by chunks of the given size.
Query lazily, by chunks of the given size.
|
#
|
public
|
lazyById(
int $chunkSize = 1000,
string|null $column = null,
string|null $alias = null,
): LazyCollection<int, TRelatedModel>
Query lazily, by chunking the results of a query by comparing IDs.
Query lazily, by chunking the results of a query by comparing IDs.
|
#
|
public
|
lazyByIdDesc(
int $chunkSize = 1000,
string|null $column = null,
string|null $alias = null,
): LazyCollection<int, TRelatedModel>
Query lazily, by chunking the results of a query by comparing IDs in descending order.
Query lazily, by chunking the results of a query by comparing IDs in descending order.
|
#
|
protected
|
prepareQueryBuilder(array $columns = ['*']): Builder<TRelatedModel>
Prepare the query builder for query execution.
Prepare the query builder for query execution.
|
#
|
public
|
getRelationExistenceQuery(Builder $query, Builder $parentQuery, $columns = ['*'])
Add the constraints for an internal relationship existence query.
Add the constraints for an internal relationship existence query.
Essentially, these queries compare on column names like whereColumn.
Overrides
Overriden by
|
#
|
public
|
getRelationExistenceQueryForSelfRelation(
Builder<TRelatedModel> $query,
Builder<TDeclaringModel> $parentQuery,
array|mixed $columns = ['*'],
): Builder<TRelatedModel>
Add the constraints for a relationship query on the same table.
Add the constraints for a relationship query on the same table.
|
#
|
public
|
getRelationExistenceQueryForThroughSelfRelation(
Builder<TRelatedModel> $query,
Builder<TDeclaringModel> $parentQuery,
array|mixed $columns = ['*'],
): Builder<TRelatedModel>
Add the constraints for a relationship query on the same table as the through parent.
Add the constraints for a relationship query on the same table as the through parent.
|
#
|
public
|
take(int $value): $this
Alias to set the "limit" value of the query.
Alias to set the "limit" value of the query.
|
#
|
public
|
limit(int $value): $this
Set the "limit" value of the query.
Set the "limit" value of the query.
|
#
|
public
|
getQualifiedFarKeyName(): string
Get the qualified foreign key on the related model.
Get the qualified foreign key on the related model.
|
#
|
public
|
getFirstKeyName(): string
Get the foreign key on the "through" model.
Get the foreign key on the "through" model.
|
#
|
public
|
getQualifiedFirstKeyName(): string
Get the qualified foreign key on the "through" model.
Get the qualified foreign key on the "through" model.
|
#
|
public
|
getForeignKeyName(): string
Get the foreign key on the related model.
Get the foreign key on the related model.
|
#
|
public
|
getQualifiedForeignKeyName(): string
Get the qualified foreign key on the related model.
Get the qualified foreign key on the related model.
|
#
|
public
|
getLocalKeyName(): string
Get the local key on the far parent model.
Get the local key on the far parent model.
|
#
|
public
|
getQualifiedLocalKeyName(): string
Get the qualified local key on the far parent model.
Get the qualified local key on the far parent model.
|
#
|
public
|
getSecondLocalKeyName(): string
Get the local key on the intermediary model.
Get the local key on the intermediary model.
|
#
|