承接 emrul1875/laravel-extra-collection 相关项目开发

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

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

emrul1875/laravel-extra-collection

Composer 安装命令:

composer require emrul1875/laravel-extra-collection

包简介

An extra collection pacakge for Laravel

README 文档

README

This is a package of Laravel Collection which can be used with laravel existing collection. You are welcome to give new idea or contribute in repository. Let's make our lives much more easier.

Installation

You can install the package via composer:

composer require emrul1875/laravel-extra-collection

Usage

The package is auto-discovered!

Add the service provider to config/app.php

Emrul1875\LaravelExtraCollection\LaravelExtraCollectionServiceProvider::class

Collections

prependValue

The prependValue() method receive 3 parameter. First 2 parameter is mandatory and 3rd parameter is optional.First parameter receive an array or string. If your collection is sequential array you can pass string as a first parameter otherwise pass an array. The array should contain key and value pair where key will be the property name of collection which should be changed and value should be the text that needs to prepend with value. You can pass true or false in thrid parameter. By default it is false. If you pass true it will skip all property which has null value.

<?php

$collection = collect([
    [
        'name' => 'John',
        'balance' => 100,
        'image' => '/uploads/image54543534.png'
    ],
    [
        'name' => 'Jonny',
        'balance' => 200
        'image' => '/uploads/image54543534.png'
    ]
]);

$updatedCollection = $collection->prependValue(["balance" => "USD ", "image": "https://dummyurl.com"], true);

/*
     [
        'name' => 'John',
        'balance' => "USD 100",
        'image' => 'https://dummyurl.com/uploads/image54543534.png'
    ],
    [
        'name' => 'Jonny',
        'balance' => "USD 200",
        'image' => 'https://dummyurl.com/uploads/image54543534.png'
    ]
*/

appendValue

The appendValue() method receive 3 parameter. First 2 parameter is mandatory and 3rd parameter is optional. First parameter receive an array or string. If your collection is sequential array you can pass string as a first parameter otherwise pass an array. The array should contain key and value pair where key will be the property name of collection which should be changed and value should be the text value that needs to append with value. You can pass true or false in thrid parameter. By default it is false. If you pass true it will skip all property which has null value.

<?php

$collection = collect([
    [
        'name' => 'John',
        'currency' => 'FCFA',
        'balance' => 100,
    ],
    [
        'name' => 'Jonny',
        'currency' => 'FCFA',
        'balance' => 400
    ]
]);

$updatedCollection = $collection->appendValue(["balance" => " FCFA"]);

/*
    [
        'name' => 'John',
        'currency' => 'FCFA',
        'balance' => '100 FCFA',
    ],
    [
        'name' => 'Jonny',
        'currency' => 'FCFA',
        'balance' => '400 FCFA'
    ]
*/

concatValue

The concatValue() method receive 3 parameter. First 2 parameter is mandatory and 3rd parameter is optional.First parameter receive new property name that should be added in the collection. Second parameter receivesarray of field name which exist in collection. Third parameter receives delimiter (comma , or space ' ').

<?php

$collection = collect([
    [
        'title' => 'Mr.'
        'firstname' => 'John',
        'lastname' => 'Doe'
    ],
    [
        'title' => 'Mr.'
        'firstname' => 'Johny',
        'lastname' => 'Doe'
    ]
]);

$updatedCollection = $collection->concatValue("fullname", ["title", "firstname", "lastname"], " ");

/*
    [
        'title' => 'Mr.'
        'firstname' => 'John',
        'lastname' => 'Doe',
        'fullname' => 'Mr. John Doe'
    ],
    [
        'title' => 'Mr.'
        'firstname' => 'Johny',
        'lastname' => 'Doe',
        'fullname' => 'Mr. Johny Doe'
    ]
*/

at

The at() method takes an integer value and returns the item at that index, allowing for positive and negative integers. Negative integers count back from the last item in the array.

<?php

$collection = collect([
    6,5,7,5,2,5,7,3,3
]);

$updatedCollection = $collection->at(3)

/*
    5
*/

$collection = collect([
    [
        'title' => 'Mr.'
        'firstname' => 'John',
        'lastname' => 'Doe'
    ],
    [
        'title' => 'Mr.'
        'firstname' => 'Johny',
        'lastname' => 'Doe'
    ]
]);

$updatedCollection = $collection->at(1)

/*
    [
        'title' => 'Mr.'
        'firstname' => 'Johny',
        'lastname' => 'Doe'
    ]
*/

find

The find() method returns the value of the first element in the provided array that satisfies the provided testing function. If no values satisfy the testing function, null is returned.

<?php

$collection = collect([
    6,5,7,5,2,5,7,3,3
]);

$updatedCollection = $collection->find(function($item) {
    return $item > 5;
});

/*
    6
*/

$collection = collect([
    [
        'title' => 'Mr.'
        'firstname' => 'John',
        'lastname' => 'Doe',
        'age' => 20
    ],
    [
        'title' => 'Mr.'
        'firstname' => 'Johny',
        'lastname' => 'Doe',
        'age' => 25
    ]
]);

$updatedCollection = $collection->find(function($item) {
    return $item->age > 15;
})

/*
    [
        'title' => 'Mr.'
        'firstname' => 'John',
        'lastname' => 'Doe',
        'age' => 20
    ],
*/

findIndex

The findIndex() method returns the index of the first element in the array that satisfies the provided testing function. Otherwise, it returns -1, indicating that no element passed the test.

<?php

$collection = collect([
    6,5,7,5,2,5,7,3,3
]);

$updatedCollection = $collection->findIndex(function($item) {
    return $item > 5;
});

/*
    0
*/

$collection = collect([
    [
        'title' => 'Mr.'
        'firstname' => 'John',
        'lastname' => 'Doe',
        'age' => 20
    ],
    [
        'title' => 'Mr.'
        'firstname' => 'Johny',
        'lastname' => 'Doe',
        'age' => 25
    ]
]);

$updatedCollection = $collection->findIndex(function($item) {
    return $item->age > 20;
})

/*
    1
*/

MIT

emrul1875/laravel-extra-collection 适用场景与选型建议

emrul1875/laravel-extra-collection 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3 次下载、GitHub Stars 达 3, 最近一次更新时间为 2021 年 10 月 29 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「extra」 「devemrul」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 emrul1875/laravel-extra-collection 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 emrul1875/laravel-extra-collection 我们能提供哪些服务?
定制开发 / 二次开发

基于 emrul1875/laravel-extra-collection 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-10-29