ElementCollection ​
- Type
- Class
- Namespace
- craft\elements
- Inherits
- craft\elements\ElementCollection »
Illuminate\Support\Collection
- Since
- 4.3.0
ElementCollection represents a collection of elements.
Public Methods ​
Method | Description |
---|---|
ids() | Returns a collection of the elements’ IDs. |
one() | |
with() | Eager-loads related elements for the collected elements. |
ids()
​
Returns a collection of the elements’ IDs.
Returns ​
\Illuminate\Support\Collection<\craft\elements\TKey,int>
one()
​
Arguments ​
$callback
$default
Returns ​
\craft\elements\TValue
–
with()
​
Eager-loads related elements for the collected elements.
See Eager-Loading Elements for a full explanation of how to work with this parameter.
Arguments ​
Returns ​
Example ​
::: code
twig
{# Fetch entries and eager-load the "Related" field’s relations onto them #}
{% set entries = craft.entries()
.collect()
.with(['related']) %}
php
// Fetch entries and eager-load the "Related" field’s relations onto them
$entries = Entry::find()
->collect()
->with(['related']);
:::