承接 werxe/laravel-collection-macros 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

werxe/laravel-collection-macros

最新稳定版本:v8.0.0

Composer 安装命令:

composer require werxe/laravel-collection-macros

包简介

Custom Laravel Collection macros.

README 文档

README

Build Status Software License Latest Version on Packagist Total Downloads

Custom Laravel Collection Macros for Laravel 9.

This package is compliant with the FIG standards PSR-1, PSR-2 and 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 Laravel PHP Version
7.x 9.x >= 8.0
6.x 8.x >= 8.0
5.x 8.x >= 7.3
4.x 7.x >= 7.2.5
3.x 6.x >= 7.2
2.x 5.8.x >= 7.1.3
1.x 5.7.x >= 7.1.3

Getting Started

Install the package via Composer 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

Available Macros

increment

Increment a value that's inside a Collection

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

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

decrement

Decrement a value that's inside a Collection

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

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

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

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

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

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

Security

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

License

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

统计信息

  • 总下载量: 25.74k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 26
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 26
  • Watchers: 3
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-03-31