designmynight / laravel-recursive-collection
A package to convert nested arrays and associative arrays into nested collections
Installs: 14 178
Dependents: 0
Suggesters: 0
Security: 0
Stars: 8
Watchers: 5
Forks: 2
Open Issues: 0
Requires
- illuminate/support: ^6.0
Requires (Dev)
- orchestra/testbench: ^3.5
- phpunit/phpunit: ^6.5
This package is auto-updated.
Last update: 2024-10-30 01:27:26 UTC
README
A service provider to add support for for converting nested arrays and associative arrays into laravel collections
Table of contents
Installation
Installation using composer:
composer require designmynight/laravel-recursive-collection
Laravel version Compatibility
And add the service provider in config/app.php
:
DesignMyNight\Laravel\RecursiveCollectionServiceProvider::class,
For usage with Lumen, add the service provider in bootstrap/app.php
.
$app->register(DesignMyNight\Laravel\RecursiveCollectionServiceProvider::class);
Example
$data = [ [ 'name' => 'John Doe', 'email' => 'john@doe.com', 'bookings' => [ [ 'venue' => 'Venue A', 'date' => '2000-01-01' 'guests' => 2 ], [ 'venue' => 'Venue B', 'date' => '2001-01-01' 'guests' => 2 ], ], ], ]; $collection = (new Collection($data))->recursive(); $collection = collect($data)->recursive(); // Shorthand