abstract class EloquentBuffer

Methods

static void
add(Model $model, string $relationName, array|null $aggregate = null)

No description

static array|null
getBuffer(Model $model, string $relationName, array|null $aggregate = null)

No description

static void
setBuffer(Model $model, string $relationName, array|null $aggregate, array $buffer)

No description

static void
load(Model $model, string $relationName, Relationship|null $relationship, Context $context, array|null $aggregate = null)

No description

static bool
loadLimitedBelongsToMany(Collection $collection, string $relationName, callable $loader)

Load a LIMITED BelongsToMany include (e.g. mentions' "first 4 mentioning posts per post") without dragging every candidate row through the database's window sort.

static void
loadAggregate(Collection $collection, string $relationName, array $aggregate, callable $loader)

Load a relation aggregate for all buffered models with ONE flat grouped query.

Details

static void add(Model $model, string $relationName, array|null $aggregate = null)

Parameters

Model $model
string $relationName
array|null $aggregate

Return Value

void

static array|null getBuffer(Model $model, string $relationName, array|null $aggregate = null)

Parameters

Model $model
string $relationName
array|null $aggregate

Return Value

array|null

static void setBuffer(Model $model, string $relationName, array|null $aggregate, array $buffer)

Parameters

Model $model
string $relationName
array|null $aggregate
array $buffer

Return Value

void

static void load(Model $model, string $relationName, Relationship|null $relationship, Context $context, array|null $aggregate = null)

Parameters

Model $model
string $relationName
Relationship|null $relationship
Context $context
array|null $aggregate

Return Value

void

static protected bool loadLimitedBelongsToMany(Collection $collection, string $relationName, callable $loader)

Load a LIMITED BelongsToMany include (e.g. mentions' "first 4 mentioning posts per post") without dragging every candidate row through the database's window sort.

Laravel compiles a limited eager load into `row_number() OVER (PARTITION BY ...)` over the relation's full select — every column of every candidate row (for posts: content blobs included) is materialized into the window just to keep a handful per parent. Instead, run the window over the KEYS alone, then fetch only the surviving rows in full. The related-resource scoping (typically visibility) applies to the narrow phase, so the kept ids are exactly the ones the one-phase query would have kept, in the same order. Returns false when this isn't a limited BelongsToMany, so the caller falls back to the plain eager load.

Parameters

Collection $collection
string $relationName
callable $loader

Return Value

bool

static protected void loadAggregate(Collection $collection, string $relationName, array $aggregate, callable $loader)

Load a relation aggregate for all buffered models with ONE flat grouped query.

Laravel's loadAggregate() emits a correlated scalar subquery per model (`select id, (select count(*) ... where outer.id = ...)`), which forces the database to re-evaluate the aggregate's constraints — for API resources, typically the full visibility scope — once per related row PER MODEL, with no chance to materialize shared subqueries. A grouped join over the relation's eager constraints computes every model's aggregate in a single flat pass instead.

Parameters

Collection $collection
string $relationName
array $aggregate
callable $loader

Return Value

void