PHPackages                             liyuze/laravel-method-chaining-macros - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. liyuze/laravel-method-chaining-macros

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

liyuze/laravel-method-chaining-macros
=====================================

1.1.0(4y ago)03MITPHPPHP ^8.0

Since May 4Pushed 4y ago1 watchersCompare

[ Source](https://github.com/liyuze/laravel-method-chaining-macros)[ Packagist](https://packagist.org/packages/liyuze/laravel-method-chaining-macros)[ Docs](https://github.com/liyuze/laravel-method-chaining-macros)[ RSS](/packages/liyuze-laravel-method-chaining-macros/feed)WikiDiscussions main Synced 3w ago

READMEChangelogDependencies (4)Versions (3)Used By (0)

Laravel 方法链式调用代理 Macros
=======================

[](#laravel-方法链式调用代理-macros)

[![Latest Version on Packagist](https://camo.githubusercontent.com/79c6b9c34b321394258fd229a74e19fa01358547cb926bf8ceadb48474c62695/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6c6979757a652f6c61726176656c2d6d6574686f642d636861696e696e672d6d6163726f732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/liyuze/laravel-method-chaining-macros)[![Total Downloads](https://camo.githubusercontent.com/80fb0558326ff6beffd4d720fd8a8960e24dc69c063aa8f4376c7b6a66856f74/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6c6979757a652f6c61726176656c2d6d6574686f642d636861696e696e672d6d6163726f732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/liyuze/laravel-method-chaining-macros)[![PHP Composer & Test](https://github.com/liyuze/laravel-method-chaining-macros/actions/workflows/php.yml/badge.svg?branch=main&event=push)](https://github.com/liyuze/laravel-method-chaining-macros/actions/workflows/php.yml)

此扩展包是针对对 `liyuze/method-chaining-proxy` 在 laravel 框架补充，通过 marcoable 特性的类快速创建方法链式调用代理器。

安装
--

[](#安装)

你可以通过 composer 进行安装:

```
composer require liyuze/laravel-method-chaining-macros
```

Macros
------

[](#macros)

- [`chaining`](#chaining)
- [`mixedChaining`](#chaining)
- [`tapChaining`](#chaining)
- [`pipeChaining`](#chaining)
- [`ifChaining`](#ifChaining)
- [`unlessChaining`](#unlessChaining)

用例
--

[](#用例)

### chaining

[](#chaining)

代理器有三种工作模式：

1. `tap` 模式，任何调用都 **不会** 影响代理的代理值。
2. `pipe` 模式，任何调用都 **会** 影响代理的代理值。
3. `mixed` 模式，只有有返回值，且不 `null` 时 **才会** 影响代理的代理值。

`tapChaining`、 `pipeChaining`、 `mixedChaining` 是快速创建这三种工作模式的代理器，`chaining` 是 `mixedChaining` 的别名。

```
collect([1,2,3])->chaining()->map(fn ($v) => $v * 2)->sum()->popValue();    //12
collect([1,2,3])->pipeChaining()->map(fn ($v) => $v * 2)->sum()->popValue();    //Collection([2,4,6])
```

更多功能查看 `liyuze/method-chaining-proxy` [文档](https://github.com/liyuze/method-chaining-proxy)

### ifChaining

[](#ifchaining)

```
$list = collect([1,2,3]);
$list->ifChaining(true)->map(fn ($v) => $v * 2)->sum()
    ->elseChaining()->map(fn ($v) => $v * 3)->avg()
    ->endIfChaining();    //12

$list->ifChaining(false)->map(fn ($v) => $v * 2)->sum()
    ->elseChaining()->map(fn ($v) => $v * 3)->avg()
    ->endIfChaining();    //6
```

### unlessChaining

[](#unlesschaining)

```
$list = collect([1,2,3]);
$list->unlessChaining(true)->map(fn ($v) => $v * 2)->sum()
    ->elseChaining()->map(fn ($v) => $v * 3)->avg()
    ->endUnlessChaining();    //6
```

配置
--

[](#配置)

发布配置文件

```
php artisan vendor:publish --provider="Liyuze\MethodChainingMacros\MethodChainingMacrosServiceProvider"
```

删除注释或添加类名来修改 macro 类列表。 通过 rename 项来指定

如果

### 测试

[](#测试)

```
composer test
```

### 修改记录

[](#修改记录)

点击 [CHANGELOG](CHANGELOG.md) 查看最近修改了哪些内容。

贡献
--

[](#贡献)

点击 [CONTRIBUTING](CONTRIBUTING.md) 查看详情

### 安全

[](#安全)

如果您发现任何与安全相关的问题，请发送电子邮件而不是使用问题追踪器。

贡献值
---

[](#贡献值)

- [Yuze Li](https://github.com/liyuze)
- [All Contributors](../../contributors)

开源协议
----

[](#开源协议)

The MIT License (MIT)。点击 [License File](LICENSE.md) 查看更多信息。

Laravel 扩展包样板
-------------

[](#laravel-扩展包样板)

本扩展包使用 [Laravel Package Boilerplate](https://laravelpackageboilerplate.com) 工具生成。

###  Health Score

23

—

LowBetter than 26% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~4 days

Total

2

Last Release

1510d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/affde44e5a0df86c5ab089ed20dd4c7dcb6958e9fcbbb0aebd3f02cf83717ba4?d=identicon)[liyuze](/maintainers/liyuze)

---

Top Contributors

[![liyuze](https://avatars.githubusercontent.com/u/4597092?v=4)](https://github.com/liyuze "liyuze (8 commits)")

---

Tags

laravelmacrosmethod-chaining

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/liyuze-laravel-method-chaining-macros/health.svg)

```
[![Health](https://phpackages.com/badges/liyuze-laravel-method-chaining-macros/health.svg)](https://phpackages.com/packages/liyuze-laravel-method-chaining-macros)
```

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3345.1M337](/packages/psalm-plugin-laravel)[renatomarinho/laravel-page-speed

Laravel Page Speed

2.5k1.7M11](/packages/renatomarinho-laravel-page-speed)[vinkius-labs/laravel-page-speed

Laravel Page Speed

2.5k9.6k1](/packages/vinkius-labs-laravel-page-speed)[emargareten/inertia-modal

Inertia Modal is a Laravel package that lets you implement backend-driven modal dialogs for Inertia apps.

90128.1k](/packages/emargareten-inertia-modal)[linkxtr/laravel-qrcode

A clean, modern, and easy-to-use QR code generator for Laravel

3614.9k](/packages/linkxtr-laravel-qrcode)[wearepixel/laravel-cart

A cart implementation for Laravel

1355.6k](/packages/wearepixel-laravel-cart)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
