Collections
Collections in PyroCMS work exactly the same as collections in Laravel.
Basic Usage
PyroCMS comes with it's own \Anomaly\Streams\Platform\Support\Collection
class that extends Laravel's base collection.
Collection::pad()
The pad
method pads the items to assure the item array is a certain size.
Returns: $this
Arguments
Key | Required | Type | Default | Description |
---|---|---|---|---|
$size |
true |
integer |
none |
The size to pad the items to. |
$value |
false |
mixed |
null |
The value to use for the pad items. |
Example
$collection->pad(10, 'No item.');
Twig
{% for item in collection.pad(10, 'No item.') %}
{{ item }}
{% endfor %}
Collection::skip()
The skip
method is a shortcut alias for slice
.
Returns: Collection
Arguments
Key | Required | Type | Default | Description |
---|---|---|---|---|
$offset |
true |
integer |
none |
The number of items to skip. |
Example
$collection->skip(10);
Twig
{% for item in collection.skip(10) %}
{{ item }}
{% endfor %}
Collection::__get()
The __get
method has been mapped to try for an item
otherwise calls the camel cased attribute method name.
Returns: mixed
Arguments
Key | Required | Type | Default | Description |
---|---|---|---|---|
$name |
true |
string |
none |
The index of the item to get or snake_case of the method to call. |
Example
// A collection of people is keyed by snake case first name
$people->ryan_thompson->favorite_color;
Twig
{{ people.ryan_thompson.favorite_color }}