This package is abandoned and no longer maintained. The author suggests using the craftcms/cms package instead.

Use Laravel Collections in Craft

3.0.0 2022-05-10 07:51 UTC

This package is auto-updated.

Last update: 2022-07-14 19:24:33 UTC


Note: This plugin has been abandoned as Craft 4 includes Collections support.

Collections plugin for Craft CMS 3.x

Use Laravel Collections in Craft



This plugin requires Craft CMS 3.0.0-beta.23 or later.


To install the plugin, follow these instructions.

  1. Open your terminal and go to your Craft project:

     cd /path/to/project
  2. Then tell Composer to load the plugin:

     composer require superbig/craft3-collections
  3. In the Control Panel, go to Settings → Plugins and click the “Install” button for Collections.

Collections Overview

Here is some good inspiration on what you can do with Collections:

Configuring Collections

Add your macros to the config file:

return [

    /** Add your macros here
     * "macros" => [
     *     'toUpper' => function () {
     *         return $this->map(function ($value) {
     *             return strtoupper($value);
     *         });
     *     },
     * ],

    "macros" => [



Using Collections

Group tags by letter:

Add this macro to your config:

return [
    'macros' => [
        'tagGroups' => function () {
            return $this->groupBy(function ($tag) {
                return substr($tag->title, 0, 1);
<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8">
    <link rel="stylesheet" href="">

<div class="section hero is-primary">
    <div class="hero-body">
        <div class="container">
            <h1 class="title">Tags</h1>
            <p class="subtitle">
                Every tag on the site.

<h2>Tag groups</h2>

<div class="section">
    <div class="container">
        <ul class="has-columns has-text-centered">
            {% set collection ='media') | collect %}
            {% for letter, tags in collection.tagGroups() %}
                <div class="letter-group">
                    <h3 class="title is-1 letter">{{ letter }}</h3>

                        {% for tag in tags %}
                            <li class="title is-5">
                                <a href="/tags/{{ tag.slug }}">{{ tag.title }}</a>
                        {% endfor %}
            {% endfor %}


Brought to you by Superbig