PHPackages                             iambib/collection-extender - 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. iambib/collection-extender

ActiveLibrary

iambib/collection-extender
==========================

Laravel/Lumen 9+ Collection Extender

1.0.3(9mo ago)02.6k↓45.6%BSD-3-ClausePHPPHP &gt;=8.0

Since Dec 17Pushed 9mo ago1 watchersCompare

[ Source](https://github.com/iamBiB/collection-extender)[ Packagist](https://packagist.org/packages/iambib/collection-extender)[ RSS](/packages/iambib-collection-extender/feed)WikiDiscussions master Synced 1mo ago

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

Laravel / Lumen Collection extender
===================================

[](#laravel--lumen-collection-extender)

This is a set of Illuminate\\Support\\Collection items I use on a daily bases

[![](https://camo.githubusercontent.com/189ce53dbbcefe1eb9052d41ac1899707c7b942caf617185ff4bc804d52cf011/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f692f636f6c6c656374696f6e2d657874656e6465722e7376673f7374796c653d666c61742d737175617265)](https://github.com/iambib/collection-extender/releases/latest)

Install
-------

[](#install)

### REQUIREMENTS

[](#requirements)

Laravel / Lumen version 9+

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

[](#installation)

```
composer  require  iambib/collection-extender
```

### Currently available

[](#currently-available)

```

$collection->recursive();

$collection->pushToKey($key, $value, ?$recursive);

$collection->toModel(?$model_class);

$collection->input($keys,?$default);

$collection->morphTo($object_class)

$collection->whereArrayContains('foo', 'bar');

$collection->whereArrayDoesntContain('foo', 'bar');

```

Examples
--------

[](#examples)

### 1. $collection-&gt;recursive()

[](#1-collection-recursive)

##### From array / multidimensional array

[](#from-array--multidimensional-array)

```

$array = [

'foo'=>'bar',

'bar'=>[

'foo'=>'Lorem',

'bar'=>'Ipsum',

],

];

```

##### to Illuminate\\Support\\Collection

[](#to-illuminatesupportcollection)

```

Illuminate\Support\Collection {#354 ▼

#items: array:2 [▼

"foo" => "bar"

"bar" => Illuminate\Support\Collection {#358 ▼

#items: array:2 [▼

"foo" => "Lorem"

"bar" => "Ipsum"

]

#escapeWhenCastingToString: false

}

]

#escapeWhenCastingToString: false

}

```

### 2. $collection-&gt;pushToKey('foo', 'newValue')

[](#2-collection-pushtokeyfoo-newvalue)

##### From single key value

[](#from-single-key-value)

```

Illuminate\Support\Collection {#354 ▼

#items: array:2 [▼

"foo" => "bar"

"bar" => Illuminate\Support\Collection {#358 ▼

#items: array:2 [▼

"foo" => "Lorem"

"bar" => "Ipsum"

]

#escapeWhenCastingToString: false

}

]

#escapeWhenCastingToString: false

}

```

##### To array key value

[](#to-array-key-value)

```

Illuminate\Support\Collection {#354 ▼

#items: array:2 [▼

"foo" => array:2 [▼

0 => "bar"

1 => "newValue"

]

"bar" => Illuminate\Support\Collection {#358 ▼

#items: array:2 [▼

"foo" => "Lorem"

"bar" => "Ipsum"

]

#escapeWhenCastingToString: false

}

]

#escapeWhenCastingToString: false

}

```

### 3. $collection-&gt;toModel works in 2 different ways

[](#3-collection-tomodel-works-in-2-different-ways)

#### With model class as param

[](#with-model-class-as-param)

#### $collection-&gt;toModel(\\App\\Models\\User::class)

[](#collection-tomodelappmodelsuserclass)

##### From collection

[](#from-collection)

```

Illuminate\Support\Collection {#352 ▼

#items: array:2 [▼

"foo" => "bar"

"bar" => array:2 [▼

"foo" => "Lorem"

"bar" => "Ipsum"

]

]

#escapeWhenCastingToString: false

}

```

#### or without model class as param

[](#or-without-model-class-as-param)

#### $collection-&gt;toModel()

[](#collection-tomodel)

Which will look for the key that is configured in collection-callback.php as a model\_class\_key

##### Config

[](#config)

```

return [

'model_class_key' => 'model_name',

];

```

##### From collection

[](#from-collection-1)

```

Illuminate\Support\Collection {#353 ▼ // packages/iambib/collection-extender/src/Providers/AppServiceProvider.php:78

#items: array:3 [▼

...

"model_name" => "App\Models\User"

]

#escapeWhenCastingToString: false

}

```

##### To Model

[](#to-model)

```

App\Models\User {#360 ▼

#attributes: array:2 [▼

"foo" => "bar"

"bar" => array:2 [▼

"foo" => "Lorem"

"bar" => "Ipsum"

]

]

#hidden: []

#visible: []

#appends: []

#fillable: []

#guarded: []

#casts: []

#rememberTokenName: "remember_token"

#autoload_relations: []

}

```

### 4. $collection-&gt;input('bar.foo')

[](#4-collection-inputbarfoo)

#### $default can be string or callback

[](#default-can-be-string-or-callback)

##### From collection

[](#from-collection-2)

```

Illuminate\Support\Collection {#352 ▼

#items: array:2 [▼

"foo" => "bar"

"bar" => array:2 [▼

"foo" => "Lorem"

"bar" => "Ipsum"

]

]

#escapeWhenCastingToString: false

}

```

##### Returns

[](#returns)

```

"Lorem"

```

### $collection-&gt;input('bar.foo.empty','Not found')

[](#collection-inputbarfooemptynot-found)

##### Returns

[](#returns-1)

```

"Not found"

```

### 5. $collection-&gt;morphTo(ApiResponse::class)

[](#5-collection-morphtoapiresponseclass)

##### Morphs current collection into an object that you need

[](#morphs-current-collection-into-an-object-that-you-need)

##### From collection

[](#from-collection-3)

```

Illuminate\Support\Collection {#354 ▼

#items: array:3 [▼

"status" => true

"data" => array:2 [▼

"foo" => "bar"

"bar" => array:2 [▼

"foo" => "Lorem"

"bar" => "Ipsum"

]

]

"message" => "Success"

]

#escapeWhenCastingToString: false

}

```

##### to ApiResponse

[](#to-apiresponse)

```

ApiResponse {#361 ▼

#status: true

#data: array:2 [▼

"foo" => "bar"

"bar" => array:2 [▼

"foo" => "Lorem"

"bar" => "Ipsum"

]

]

#message: "Success"

#errors: null

}

```

### 5. $collection-&gt;whereArrayContains('foo', 'bar')

[](#5-collection-wherearraycontainsfoo-bar)

##### Searches bar inside foo.

[](#searches-bar-inside-foo)

##### From collection

[](#from-collection-4)

```

  #items: array:2 [▼
    0 => array:4 [▼
      ...
      "foo" => array:2 [▼
        0 => "bar"
        1 => "tar"
      ]
    ]
    1 => array:4 [▼
      ...
      "foo" => array:1 [▼
        0 => "tar"
      ]
    ]
  ]
  #escapeWhenCastingToString: false }

```

##### Returns

[](#returns-2)

```

items: array:1 [▼
    0 => array:4 [▼
      ...
      "foo" => array:2 [▼
        0 => "bar"
        1 => "tar"
      ]
    ]
  ]
  #escapeWhenCastingToString: false }

```

### 5. $collection-&gt;whereArrayDoesntContain('foo', 'bar')

[](#5-collection-wherearraydoesntcontainfoo-bar)

##### Searches bar inside foo.

[](#searches-bar-inside-foo-1)

##### From collection

[](#from-collection-5)

```

  #items: array:2 [▼
    0 => array:4 [▼
      ...
      "foo" => array:2 [▼
        0 => "bar"
        1 => "tar"
      ]
    ]
    1 => array:4 [▼
      ...
      "foo" => array:1 [▼
        0 => "tar"
      ]
    ]
  ]
  #escapeWhenCastingToString: false }

```

##### Returns

[](#returns-3)

```

items: array:1 [▼
    0 => array:4 [▼
      ...
      "foo" => array:2 [▼
        1 => "tar"
      ]
    ]
  ]
  #escapeWhenCastingToString: false }

```

Support
=======

[](#support)

Hey dude! If you like it .. well [![beers](https://camo.githubusercontent.com/cfad5a164cc9dda21bbca1e83f53726fb2db29c5da944ec34a0a9e844e89981f/68747470733a2f2f6769746875622e6769746875626173736574732e636f6d2f696d616765732f69636f6e732f656d6f6a692f756e69636f64652f31663337622e706e67)](https://camo.githubusercontent.com/cfad5a164cc9dda21bbca1e83f53726fb2db29c5da944ec34a0a9e844e89981f/68747470733a2f2f6769746875622e6769746875626173736574732e636f6d2f696d616765732f69636f6e732f656d6f6a692f756e69636f64652f31663337622e706e67) or a [![coffee](https://camo.githubusercontent.com/5dbab2895c826dfbceb6f6661d7b3d04882cc0a26b969ea81888c45905af7443/68747470733a2f2f6769746875622e6769746875626173736574732e636f6d2f696d616765732f69636f6e732f656d6f6a692f756e69636f64652f323631352e706e67)](https://camo.githubusercontent.com/5dbab2895c826dfbceb6f6661d7b3d04882cc0a26b969ea81888c45905af7443/68747470733a2f2f6769746875622e6769746875626173736574732e636f6d2f696d616765732f69636f6e732f656d6f6a692f756e69636f64652f323631352e706e67) would be nice :D

[![coffee](https://camo.githubusercontent.com/e9aa2120403febc22384c319070cfa5c36d1849fa75fdb74c1dfe83a8c136ef2/68747470733a2f2f7777772e6275796d6561636f666665652e636f6d2f6173736574732f696d672f637573746f6d5f696d616765732f626c61636b5f696d672e706e67)](https://www.buymeacoffee.com/fhc0C7A)

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance58

Moderate activity, may be stable

Popularity21

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

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 ~203 days

Total

4

Last Release

274d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/192c69fa4d5c5609f566b9e0f6eb0694f5ca3d70c57655189067a9b4dee8c34b?d=identicon)[iamBiB](/maintainers/iamBiB)

---

Top Contributors

[![iamBiB](https://avatars.githubusercontent.com/u/12171894?v=4)](https://github.com/iamBiB "iamBiB (8 commits)")

### Embed Badge

![Health badge](/badges/iambib-collection-extender/health.svg)

```
[![Health](https://phpackages.com/badges/iambib-collection-extender/health.svg)](https://phpackages.com/packages/iambib-collection-extender)
```

###  Alternatives

[illuminate/database

The Illuminate Database package.

2.8k52.4M9.4k](/packages/illuminate-database)[illuminate/support

The Illuminate Support package.

582107.1M34.5k](/packages/illuminate-support)[illuminate/filesystem

The Illuminate Filesystem package.

15161.6M2.6k](/packages/illuminate-filesystem)[illuminate/validation

The Illuminate Validation package.

18936.7M1.4k](/packages/illuminate-validation)[illuminate/queue

The Illuminate Queue package.

20331.4M1.2k](/packages/illuminate-queue)[timacdonald/log-fake

A drop in fake logger for testing with the Laravel framework.

4235.9M56](/packages/timacdonald-log-fake)

PHPackages © 2026

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