daikazu/laravel-recursive-collection

Convert nested arrays, associative, and multidimensional arrays into nested collections.
30,513 1
Install
composer require daikazu/laravel-recursive-collection
Latest Version:v1.0.11
License:MIT
Last Updated:Mar 25, 2024
Links: GitHub  ·  Packagist
Maintainer: daikazu

Laravel Recursive Collection

Convert nested arrays, associative, and multidimensional arrays into nested collections.

Install

Install using composer.

composer require daikazu/laravel-recursive-collection

Setup

NOTE This package supports Laravel 5.5 auto-discovery, so you can skip the setup if you are using 5.5 and above.

And add the service provider in config/app.php:

Daikazu\Laravel\RecursiveCollectionServiceProvider::class,

Usage

$data = [
    "foo" => "bar",
    "a"   => [1, 2, 3],
    "b"   => [
        [1, 2, 3],
        [
            "4" => "",
            "5" => "",
            "3" => "",
        ],
    ],
];

$collection = (new Collection($data))->recursive();
$collection = collect($data)->recursive();

Related Packages

designmynight/laravel-recursive-collection

A package to convert nested arrays and associative arrays into nested collection...

27,446 8
collector/collector

A collection library inspired by Laravel Collections, built using generators to...

208 15
mb4it/collections

Separate collections Illuminate\Support\Collections

390 0
mookofe/laravel-support

Awesome enhancements for your current Laravel Models, Collections and more.

12 3

Version History

Version Released Laravel License
v1.0.11 >=5.6 MIT
v1.0.10 ^5.6||^6.0||^7.0||^8.0||^9.0||^10.0 MIT
v1.0.7 5.6.*|5.7.*|5.8.*|^6.0|^7.0|^8.0|^9.0 MIT
v1.0.6 5.6.*|5.7.*|5.8.*|^6.0|^7.0|^8.0 MIT
v1.0.5 5.6.*|5.7.*|5.8.*|^6.0|^7.0 MIT