werxe/laravel-collection-macros
Composer 安装命令:
composer require werxe/laravel-collection-macros
包简介
Custom Laravel Collection macros.
关键字:
README 文档
README
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.
- Check out our contributing guide
- Look at our code of conduct
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.
werxe/laravel-collection-macros 适用场景与选型建议
werxe/laravel-collection-macros 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 27.1k 次下载、GitHub Stars 达 26, 最近一次更新时间为 2019 年 03 月 31 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「laravel」 「collection」 「macros」 「werxe」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 werxe/laravel-collection-macros 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 werxe/laravel-collection-macros 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 werxe/laravel-collection-macros 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
This package provides type-safe extension of the laravel collection, forcing a single type of object.
Traits to build collections of specific objects
ItalyStrap Helpers
Froq! Collection.
Model and Collection classes
A simple collection library for PHP.
统计信息
- 总下载量: 27.1k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 26
- 点击次数: 14
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-03-31