https://github.com/sjelfull/craft3-collections
Clean up those complex templates with Laravel Collections
https://github.com/sjelfull/craft3-collections
craft craft3 craftcms craftcms-plugin
Last synced: 5 months ago
JSON representation
Clean up those complex templates with Laravel Collections
- Host: GitHub
- URL: https://github.com/sjelfull/craft3-collections
- Owner: sjelfull
- License: mit
- Archived: true
- Created: 2017-11-18T17:26:53.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2022-07-14T19:24:30.000Z (almost 4 years ago)
- Last Synced: 2024-08-10T08:49:11.566Z (almost 2 years ago)
- Topics: craft, craft3, craftcms, craftcms-plugin
- Language: PHP
- Homepage: https://superbig.co
- Size: 44.9 KB
- Stars: 24
- Watchers: 3
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
>**Note: This plugin has been abandoned as Craft 4 includes Collections support.**
# Collections plugin for Craft CMS 3.x
Use Laravel Collections in Craft

## Requirements
This plugin requires Craft CMS 3.0.0-beta.23 or later.
## Installation
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:
- [Collections documentation](https://laravel.com/docs/5.5/collections)
- [Laravel Collections: PHP Arrays On Steroids](https://scotch.io/tutorials/laravel-collections-php-arrays-on-steroids)
- [Laravel Collections Examples on GitHub](https://github.com/fakiolinho/laravel-collections-examples)
- [Laravel Collections “when” Method](https://laravel-news.com/laravel-collections-when-method)
- [Code Bright: Eloquent Collections](https://daylerees.com/codebright-eloquent-collections/)
- [Refactoring To Collection](https://adamwathan.me/refactoring-to-collections/)
- [10 less-known (but awesome!) Laravel Collections methods](http://laraveldaily.com/10-less-known-but-awesome-laravel-collections-methods/)
## Configuring Collections
Add your macros to the config file:
```php
[
* 'toUpper' => function () {
* return $this->map(function ($value) {
* return strtoupper($value);
* });
* },
* ],
*
*/
"macros" => [
],
];
```
## Using Collections
### Group tags by letter:
Add this macro to your config:
```php
[
'tagGroups' => function () {
return $this->groupBy(function ($tag) {
return substr($tag->title, 0, 1);
});
}
],
];
```
```twig
Document
Tags
Every tag on the site.
Tag groups
{% set collection = craft.tags.group('media') | collect %}
{% for letter, tags in collection.tagGroups() %}
{% endfor %}
```
Brought to you by [Superbig](https://superbig.co)