trait HasEagerLoading

This is directed at eager loading relationships apart from the request includes.

Properties

protected (string|callable)[] $loadRelations
protected array<string,callable> $loadRelationWhere

Methods

eagerLoad(array|string|Closure $relations)

Eager loads relationships needed for serializer logic.

eagerLoadWhenIncluded(array $includedToRelations)

Eager load relations when a relation is included in the serialized response.

eagerLoadWhere(string $relation, callable $callback)

Allows loading a relationship with additional query modification.

void
loadRelations(Collection $models, Context $context, array $included = [])

Eager loads relationships before serialization.

array
compileSimpleEagerLoads(Context $context, array $included)

No description

array
compileWhereEagerLoads(Context $context)

No description

array
getEagerLoadsFor(string $included, Context $context)

No description

array
getWhereEagerLoadsFor(string $included, Context $context)

No description

Details

HasEagerLoading eagerLoad(array|string|Closure $relations)

Eager loads relationships needed for serializer logic.

Parameters

array|string|Closure $relations

Return Value

HasEagerLoading

HasEagerLoading eagerLoadWhenIncluded(array $includedToRelations)

Eager load relations when a relation is included in the serialized response.

Parameters

array $includedToRelations An array of included relation to relations to load 'includedRelation' => ['relation1', 'relation2']

Return Value

HasEagerLoading

HasEagerLoading eagerLoadWhere(string $relation, callable $callback)

Allows loading a relationship with additional query modification.

Parameters

string $relation
callable $callback The callback to modify the query, should accept: - \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Relations\Relation $query: A query object. - Context $context: An instance of the API context. - array $relations: An array of relations that are to be loaded.

Return Value

HasEagerLoading

protected void loadRelations(Collection $models, Context $context, array $included = [])

Eager loads relationships before serialization.

Parameters

Collection $models
Context $context
array $included

Return Value

void

protected array compileSimpleEagerLoads(Context $context, array $included)

Parameters

Context $context
array $included

Return Value

array

protected array compileWhereEagerLoads(Context $context)

Parameters

Context $context

Return Value

array

array getEagerLoadsFor(string $included, Context $context)

Parameters

string $included
Context $context

Return Value

array

array getWhereEagerLoadsFor(string $included, Context $context)

Parameters

string $included
Context $context

Return Value

array