designmynight/laravel-recursive-collection

一个将嵌套数组和关联数组转换为嵌套集合的包

v2.0.0 2023-11-01 15:17 UTC

This package is auto-updated.

Last update: 2024-08-30 01:07:09 UTC


README

Latest Stable Version Total Downloads

一个服务提供者,用于添加将嵌套数组和关联数组转换为 Laravel 集合的支持

目录

安装

使用 composer 安装

composer require designmynight/laravel-recursive-collection

Laravel 版本兼容性

并在 config/app.php 中添加服务提供者

DesignMyNight\Laravel\RecursiveCollectionServiceProvider::class,

对于与 Lumen 的使用,请在 bootstrap/app.php 中添加服务提供者。

$app->register(DesignMyNight\Laravel\RecursiveCollectionServiceProvider::class);

示例

$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