PHPackages                             pion/laravel-support-collection - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. pion/laravel-support-collection

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

pion/laravel-support-collection
===============================

The support classes for the Laravels collection

v1.1.3(1y ago)06.5k↓50%2MITPHP

Since Jun 18Pushed 1y ago1 watchersCompare

[ Source](https://github.com/pionl/laravel-support-collection)[ Packagist](https://packagist.org/packages/pion/laravel-support-collection)[ Fund](https://revolut.me/martinpv7n)[ GitHub Sponsors](https://github.com/pionl)[ RSS](/packages/pion-laravel-support-collection/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)Dependencies (1)Versions (5)Used By (0)

Laravel Collection support package
==================================

[](#laravel-collection-support-package)

A mix of classes for improving the Collection.

Installation
------------

[](#installation)

```
composer require pion/laravel-support-collection

```

NestedObjectCollection
----------------------

[](#nestedobjectcollection)

Creates a nested collection from flat collection to child nested collection based on parent property and id property.

It's expected that the values are **objects**, it will insert the childs into the desired property.

All childs are stored to childs property in the object. Can be empty.

You can call all Collection methods on the NestedObjectCollection object, all method calls are passed into the collection

### Construct

[](#construct)

Groups the items by the parent property and loops from the top of tree (null property or different value) and adds childs to the object.

*Parameters*

- Collection `$items`
- string `$parentProperty` the property name to get the parent id
- string `$idProperty` the property name to get the id value
- string `$rootIndexKeyOnGroup` the index key for getting the root elements. When the parent property value returns null, it will be empty string.
- string `$propertyForChildren` the property name to store the children

    public function \_\_construct(Collection $items, $parentProperty = "parent\_id", $idProperty = "id", $rootIndexKeyOnGroup = "", $propertyForChildren = "childs")

### Eloquent usage

[](#eloquent-usage)

It's advised to set a property in the Eloquent model to prevent creating childs into the attributes. For default property name you can use the `ChildsCollectionTrait`. This provides a public `$childs` property for your Eloquent model

### Example

[](#example)

```
$object1 = new stdClass();
$object1->id = 1;

// this is the root!
$object1->parent_id = null;

$object2 = new stdClass();

$object2->id = 2;
$object2->parent_id = 2;

$object3 = new stdClass();

$object3->id = 3;
$object3->parent_id = 1;

$example = new \Pion\Support\Collection\NestedObjectCollection(new \Illuminate\Support\Collection([
    $object1, $object2, $object3
]));

$collection = $example->getCollection();

```

This example will create a collection of single item (the `$object1`). This objects will have a new property $childs which is holding a Collection of single item `$object2` that holds again property $childs with a single item `$object3`

GroupedCollection
-----------------

[](#groupedcollection)

Enables a quick how to build a grouped collection. Just add a new item to the collection with given group key and the value. Optionally you can provide also the key for the value.

```
public function add($groupKey, $value, $key = null)

```

### Example

[](#example-1)

The use of the collection is same as standard collection.

```
$groupedCollection = new GroupedCollection();
$groupedCollection->add("1", "test 1");
$groupedCollection->add("1", "test 2");
$groupedCollection->add("1", "test 3");
$groupedCollection->add("2", "test 2-1");
$groupedCollection->add("2", "test 2-2");

```

This will result in a collection of items with a collection object. If you export the collection into array you will grouped array as expected.

```
var_dump($groupedCollection->toArray());

array(2) {
  [1] =>
  array(3) {
    [0] =>
    string(6) "test 1"
    [1] =>
    string(6) "test 2"
    [2] =>
    string(6) "test 3"
  }
  [2] =>
  array(2) {
    [0] =>
    string(8) "test 2-1"
    [1] =>
    string(8) "test 2-2"
  }
}

```

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance36

Infrequent updates — may be unmaintained

Popularity24

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~1010 days

Total

4

Last Release

583d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/ad0f2a11e630f5f386cb8544d42f0c56c2b89258172dae581a33dddcc5de1d83?d=identicon)[pionl](/maintainers/pionl)

---

Top Contributors

[![h4kuna](https://avatars.githubusercontent.com/u/335722?v=4)](https://github.com/h4kuna "h4kuna (1 commits)")[![jakubdibala](https://avatars.githubusercontent.com/u/7672104?v=4)](https://github.com/jakubdibala "jakubdibala (1 commits)")[![pionl](https://avatars.githubusercontent.com/u/1878831?v=4)](https://github.com/pionl "pionl (1 commits)")

### Embed Badge

![Health badge](/badges/pion-laravel-support-collection/health.svg)

```
[![Health](https://phpackages.com/badges/pion-laravel-support-collection/health.svg)](https://phpackages.com/packages/pion-laravel-support-collection)
```

###  Alternatives

[barryvdh/laravel-ide-helper

Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.

14.9k123.0M687](/packages/barryvdh-laravel-ide-helper)[orchestra/canvas

Code Generators for Laravel Applications and Packages

21017.2M158](/packages/orchestra-canvas)[illuminate/pipeline

The Illuminate Pipeline package.

9446.6M213](/packages/illuminate-pipeline)[illuminate/pagination

The Illuminate Pagination package.

10532.5M862](/packages/illuminate-pagination)[spatie/laravel-pjax

A pjax middleware for Laravel 5

513371.8k11](/packages/spatie-laravel-pjax)[spatie/laravel-mix-preload

Add preload and prefetch links based your Mix manifest

169176.0k2](/packages/spatie-laravel-mix-preload)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
