---
title: Collections
---

# Collections

<div class="documentation__toc"></div>

@TODO review

## Introduction

Collections in PyroCMS work exactly the same as [collections in Laravel](https://laravel.com/docs/5.3/collections).

## 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

<table class="table table-bordered table-striped">

<thead>

<tr>

<th>Key</th>

<th>Required</th>

<th>Type</th>

<th>Default</th>

<th>Description</th>

</tr>

</thead>

<tbody>

<tr>

<td>

$size

</td>

<td>

true

</td>

<td>

integer

</td>

<td>

none

</td>

<td>

The size to pad the items to.

</td>

</tr>

<tr>

<td>

$value

</td>

<td>

false

</td>

<td>

mixed

</td>

<td>

null

</td>

<td>

The value to use for the pad items.

</td>

</tr>

</tbody>

</table>

#### 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

<table class="table table-bordered table-striped">

<thead>

<tr>

<th>Key</th>

<th>Required</th>

<th>Type</th>

<th>Default</th>

<th>Description</th>

</tr>

</thead>

<tbody>

<tr>

<td>

$offset

</td>

<td>

true

</td>

<td>

integer

</td>

<td>

none

</td>

<td>

The number of items to skip.

</td>

</tr>

</tbody>

</table>

#### 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

<table class="table table-bordered table-striped">

<thead>

<tr>

<th>Key</th>

<th>Required</th>

<th>Type</th>

<th>Default</th>

<th>Description</th>

</tr>

</thead>

<tbody>

<tr>

<td>

$name

</td>

<td>

true

</td>

<td>

string

</td>

<td>

none

</td>

<td>

The index of the item to get or snake_case of the method to call.

</td>

</tr>

</tbody>

</table>

#### Example

    // A collection of people is keyed by snake case first name
    $people->ryan_thompson->favorite_color;

###### Twig

    {{ people.ryan_thompson.favorite_color }}

