PHPackages                             werxe/laravel-collection-macros - 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. werxe/laravel-collection-macros

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

werxe/laravel-collection-macros
===============================

Custom Laravel Collection macros.

v8.0.0(3y ago)2627.7k2[1 PRs](https://github.com/bluebeetlept/laravel-collection-macros/pulls)MITPHPPHP ^8.2

Since Mar 31Pushed 3mo ago3 watchersCompare

[ Source](https://github.com/bluebeetlept/laravel-collection-macros)[ Packagist](https://packagist.org/packages/werxe/laravel-collection-macros)[ Docs](https://werxe.com)[ RSS](/packages/werxe-laravel-collection-macros/feed)WikiDiscussions 7.x Synced 2d ago

READMEChangelog (10)Dependencies (5)Versions (21)Used By (0)

Laravel Collection Macros
-------------------------

[](#laravel-collection-macros)

[![Build Status](https://github.com/werxe/laravel-collection-macros/workflows/Tests/badge.svg?branch=7.x)](https://github.com/werxe/laravel-collection-macros/actions?query=workflow%3ATests)[![Software License](https://camo.githubusercontent.com/6a1be71533247cc7ecfda308e564791f6da91ba94a659a986a5427501cccc7b5/68747470733a2f2f706f7365722e707567782e6f72672f77657278652f6c61726176656c2d636f6c6c656374696f6e2d6d6163726f732f6c6963656e7365)](https://opensource.org/licenses/MIT)[![Latest Version on Packagist](https://camo.githubusercontent.com/040d2831c0da68ebd46857d913f598453e5bb3673cce8d3f858c88382f5876be/68747470733a2f2f706f7365722e707567782e6f72672f77657278652f6c61726176656c2d636f6c6c656374696f6e2d6d6163726f732f76657273696f6e)](https://packagist.org/packages/werxe/laravel-collection-macros)[![Total Downloads](https://camo.githubusercontent.com/9b4967cc3ba901f67ef5469fce162ebea8eb903dc85c8effbebfba8d4be86a63/68747470733a2f2f706f7365722e707567782e6f72672f77657278652f6c61726176656c2d636f6c6c656374696f6e2d6d6163726f732f646f776e6c6f616473)](https://packagist.org/packages/werxe/laravel-collection-macros)

Custom Laravel Collection Macros for Laravel 9.

This package is compliant with the FIG standards [PSR-1](http://www.php-fig.org/psr/psr-1/), [PSR-2](http://www.php-fig.org/psr/psr-2/) and [PSR-4](http://www.php-fig.org/psr/psr-4/) to ensure a high level of interoperability between shared PHP. If you notice any compliance oversights, please send a patch via pull request.

Version Matrix
--------------

[](#version-matrix)

VersionLaravelPHP Version7.x9.x&gt;= 8.06.x8.x&gt;= 8.05.x8.x&gt;= 7.34.x7.x&gt;= 7.2.53.x6.x&gt;= 7.22.x5.8.x&gt;= 7.1.31.x5.7.x&gt;= 7.1.3Getting Started
---------------

[](#getting-started)

Install the package via [Composer](https://getcomposer.org/) by running:

```
composer require werxe/laravel-collection-macros

```

By default all macros are enabled and the macro name is the lower cased version of the macro class.

If you want to customize which macros are enabled or just rename the macro name, you can do so by publishing the configuration file, by running:

```
php artisan vendor:publish --tag="werxe:collection-macros.config"

```

The configuration file is now published at `config/werxe/collection-macros/config.php`.

Documentation
-------------

[](#documentation)

### Available Macros

[](#available-macros)

- [`increment`](#increment)
- [`decrement`](#decrement)
- [`ksort`](#ksort)
- [`krsort`](#krsort)
- [`recursive`](#recursive)

### `increment`

[](#increment)

Increment a value that's inside a Collection

```
$collection = collect([
    'total' => 1,
]);

$collection->increment('total', 2); // 3
```

### `decrement`

[](#decrement)

Decrement a value that's inside a Collection

```
$collection = collect([
    'total' => 3,
]);

$collection->decrement('total', 2); // 1
```

### `ksort`

[](#ksort)

Sorts the Collection by its keys.

```
$collection = collect(['d' => 'lemon', 'a' => 'orange', 'b' => 'banana', 'c' => 'apple']);

$collection->ksort(); // ['a' => 'orange', 'b' => 'banana', 'c' => 'apple', 'd' => 'lemon']
```

### `krsort`

[](#krsort)

Sorts the Collection by its keys in the reverse order

```
$collection = collect(['d' => 'lemon', 'a' => 'orange', 'b' => 'banana', 'c' => 'apple']);

$collection->krsort(); // ['d' => 'lemon', 'c' => 'apple', 'b' => 'banana', 'a' => 'orange']
```

### `recursive`

[](#recursive)

Recursively convert nested arrays into Laravel Collections.

```
$collection = collect([
    'name' => 'John Doe',
    'emails' => [
        'john@doe.com',
        'john.doe@example.com',
    ],
    'contacts' => [
        [
            'name' => 'Richard Tea',
            'emails' => [
                'richard.tea@example.com',
            ],
        ],
    ],
]);

// Convert the nested arrays into Collections
$convertedCollection = $collection->recursive();

// Get the contacts as a Collection
$contacts = $convertedCollection->get('contacts');
```

Contributing
------------

[](#contributing)

Thank you for your interest in Laravel Collection Macros. Here are some of the many ways to contribute.

- Check out our [contributing guide](/.github/CONTRIBUTING.md)
- Look at our [code of conduct](/.github/CODE_OF_CONDUCT.md)

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

License
-------

[](#license)

Laravel Collection Macros is licenced under the MIT License (MIT). Please see the [license file](LICENSE) for more information.

###  Health Score

51

—

FairBetter than 95% of packages

Maintenance54

Moderate activity, may be stable

Popularity37

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity82

Battle-tested with a long release history

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

Recently: every ~202 days

Total

19

Last Release

1116d ago

Major Versions

3.x-dev → v4.0.02020-03-10

4.x-dev → v5.0.02020-09-26

v5.0.1 → v6.0.02021-05-05

6.x-dev → v7.0.02022-06-15

7.x-dev → v8.0.02023-07-22

PHP version history (7 changes)v1.0.0PHP ^7.1.3

v3.0.0PHP ^7.2

v4.0.0PHP ^7.2.5

v5.0.0PHP ^7.3

5.x-devPHP ^7.3 || ^8.0

v6.0.0PHP ^8.0

v8.0.0PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/489a2b88511015a9d100f1402fe5ed0c20e70c8e557ccabf7bf97376d877ec9c?d=identicon)[werxe](/maintainers/werxe)

---

Top Contributors

[![brunogaspar](https://avatars.githubusercontent.com/u/2285372?v=4)](https://github.com/brunogaspar "brunogaspar (40 commits)")

---

Tags

collectionlaravelmacrosphpphplaravelcollectionmacroswerxe

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/werxe-laravel-collection-macros/health.svg)

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

###  Alternatives

[emargareten/inertia-modal

Inertia Modal is a Laravel package that lets you implement backend-driven modal dialogs for Inertia apps.

90157.6k](/packages/emargareten-inertia-modal)[lazerg/laravel-enum-pro

A powerful PHP enum extension with collection support, random selection, and magic static calls

4319.7k](/packages/lazerg-laravel-enum-pro)[forjedio/inertia-table

Backend-driven dynamic tables for Laravel + Inertia.js

272.0k](/packages/forjedio-inertia-table)[tomshaw/electricgrid

A feature-rich Livewire package designed for projects that require dynamic, interactive data tables.

119.8k](/packages/tomshaw-electricgrid)

PHPackages © 2026

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