ElementCollection

Type
Class
Namespace
craft\elements
Inherits
craft\elements\ElementCollection » Illuminate\Support\Collection
Since
4.3.0

ElementCollection represents a collection of elements.

View source (opens new window)

# Public Methods

Method Description
ids() Returns a collection of the elements’ IDs.
with() Eager-loads related elements for the collected elements.

# ids()

Returns a collection of the elements’ IDs.

View source (opens new window)

Returns

\Illuminate\Support\Collection<\craft\elements\TKey,int>

# with()

Eager-loads related elements for the collected elements.

See Eager-Loading Elements (opens new window) for a full explanation of how to work with this parameter.

View source (opens new window)

Arguments

Returns

$this

Example

{# Fetch entries and eager-load the "Related" field’s relations onto them #}
{% set entries = craft.entries()
  .collect()
  .with(['related']) %}