From 692b8401dfebe56df2191f5ed1a3e107ed9a1ffa Mon Sep 17 00:00:00 2001 From: Alex Vanderbist Date: Fri, 4 Aug 2017 16:12:45 +0200 Subject: [PATCH] updated readme and changelog --- CHANGELOG.md | 3 +++ README.md | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f54f3a5..b93a7a5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ All notable changes to `laravel-collection-macros` will be documented in this file +## 2.5.0 - 2017-08-03 +- Added customization options for `sectionBy` + ## 2.4.0 - 2017-08-02 - Added: `sectionBy` diff --git a/README.md b/README.md index 2b14d4f..2d06e3a 100644 --- a/README.md +++ b/README.md @@ -282,6 +282,43 @@ $collection->sectionBy('module'); // ]; ``` +You can also pass the `$sectionKey`, `$itemsKey` and `$preserveKeys` parameters to customize the sectioned output: + +```php +$collection = collect([ + 'lesson1' => ['name' => 'Lesson 1', 'module' => 'Basics'], + 'lesson2' => ['name' => 'Lesson 2', 'module' => 'Basics'], + 'lesson3' => ['name' => 'Lesson 3', 'module' => 'Advanced'], + 'lesson4' => ['name' => 'Lesson 4', 'module' => 'Advanced'], + 'lesson5' => ['name' => 'Lesson 5', 'module' => 'Basics'], +]); + +$collection->sectionBy('module', 'moduleName', 'lessons', true); + +// [ +// [ +// 'moduleName' => 'Basics', +// 'lessons' => [ +// 'lesson1' => ['name' => 'Lesson 1', 'module' => 'Basics'], +// 'lesson2' => ['name' => 'Lesson 2', 'module' => 'Basics'], +// ], +// ], +// [ +// 'moduleName' => 'Advanced', +// 'lessons' => [ +// 'lesson3' => ['name' => 'Lesson 3', 'module' => 'Advanced'], +// 'lesson4' => ['name' => 'Lesson 4', 'module' => 'Advanced'], +// ], +// ], +// [ +// 'moduleName' => 'Basics', +// 'lessons' => [ +// 'lesson5' => ['name' => 'Lesson 5', 'module' => 'Basics'], +// ], +// ], +// ]; +``` + ### `after` Get the next item from the collection.