anthony-dee/collection-macros 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

anthony-dee/collection-macros

Composer 安装命令:

composer require anthony-dee/collection-macros

包简介

Set of useful extension macros to the laravel Collection class

README 文档

README

Latest Version on Packagist This package houses some macros that extend the Laravel Collection. It currently only contains one, pluckThenGroupBy

Installation

You can install the package via composer:

composer require anthony-dee/collection-macros

Usage

pluckThenGroupBy

A combination of the native groupBy and pluck methods. It takes up to three keys and at least two. The first is the $groupBy key, the second ($pluckValue) is value to pluck and the third, if given, is used to key the plucked values.

A good use for this is to prepare a collection to be used as a data source for optgroup labels and option values and text.

$collection = collect([
            ['id' => 1, 'name' => 'Lesson 1', 'module' => 'Basics', 'reward' => 'gold'],
            ['id' => 2, 'name' => 'Lesson 2', 'module' => 'Basics', 'reward' => 'silver'],
            ['id' => 3, 'name' => 'Lesson 3', 'module' => 'Advanced', 'reward' => 'silver'],
            ['id' => 4, 'name' => 'Lesson 4', 'module' => 'Advanced', 'reward' => 'gold'],
            ['id' => 5, 'name' => 'Lesson 4', 'module' => 'Advanced', 'reward' => 'silver'],
        ]);

$collection->pluckThenGroupBy('module', 'reward', 'name');

// [
//   "Basics" =>  [
//     "Lesson 1" => "gold"
//     "Lesson 2" => "silver"
//   ]
//   "Advanced" =>  [
//     "Lesson 3" => "silver"
//     "Lesson 4" => "silver"
//   ]
// ]

Contributing

Please see CONTRIBUTING for details.

Credits

License

The MIT License (MIT). Please see License File for more information.

Laravel Package Boilerplate

This package was generated using the Laravel Package Boilerplate.

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-04-19

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固