PHPackages                             lookfeel/laravel-eloquent-append-automate - 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. lookfeel/laravel-eloquent-append-automate

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

lookfeel/laravel-eloquent-append-automate
=========================================

根据 appends 配置的关联字段映射关系，自动维护需要的 appends。

1.2.5(4y ago)56.1k↓75%MITPHPPHP &gt;=5.6.4CI failing

Since Aug 1Pushed 4y ago1 watchersCompare

[ Source](https://github.com/terranc/laravel-eloquent-append-automate)[ Packagist](https://packagist.org/packages/lookfeel/laravel-eloquent-append-automate)[ RSS](/packages/lookfeel-laravel-eloquent-append-automate/feed)WikiDiscussions master Synced 2w ago

READMEChangelog (8)Dependencies (7)Versions (9)Used By (0)

Laravel Eloquent Append Automation
==================================

[](#laravel-eloquent-append-automation)

> 撸了个包，解决困扰我很久的一个问题，当给定了 $appends 之后，在某些限定了查询字段的查询时，会因没查询 accessor 中涉及的字段而导致错误，而每次在使用的时候再去动态 append 又很烦，变化时维护起来很心累。

根据 appends 配置的关联字段映射关系，自动维护需要的 appends。

安装
--

[](#安装)

```
$ composer require lookfeel/laravel-eloquent-append-automate
```

> **Note:** **Laravel Eloquent Append Automation** requires Laravel 5.6+.

使用
--

[](#使用)

### Appends 字段映射配置

[](#appends-字段映射配置)

如下所见，您仅仅需要给需要做字段映射的 append 添加对应的键名，键名为字映射字段名称，程序将自动根据映射关系，判断是否需要移除这些 append，以避免因查询中缺少该字段而引起的错误。

##### Model:

[](#model)

```
use Lookfeel\AppendAutomate\Database\Eloquent\Model;

class User extend Modal {
    protected $appends = [
        'first_letter',
        'firstname|lastname' => 'fullname',     // firstname 和 lastname 字段缺一不可，否则不返回 fullname
        'gender' => 'gender_text',  // gender 是一个 int 字段，0:女，1:男
        'status' => 'status_text', // status 是一个 int 字段，0:禁用，1:启用
        'gender_text' => 'access',
        'access' => 'access_text',
    ];
    public function getFirstLetterAttribute()
    {
        return substr($this->firstname, 0, 1);
    }
    public function getFullnameAttribute()
    {
        return $this->firstname . ' ' . $this->lastname;
    }
    public function getGenderTextAttribute()
    {
        return ['女', '男'][$this->gender];
    }
    public function getStatusTextAttribute()
    {
        return ['启用', '禁用'][$this->status];
    }
    public function getAccessAttribute()
    {
        return $this->gender_text === 'Female';
    }
    public function getAccessTextAttribute()
    {
        return $this->access ? 'can' : 'Can not';
    }
}
```

##### Controller

[](#controller)

```
User::select(['id', 'firstname', 'gender'])->firstOrFail();

/***
{
    "id": 1,
    "first_letter": "T",
    "firstname": "Terran",
    "gender": 1,
    "gender_text": "男",
    "access": 1,
    "access_text": "can"
}
*/
```

### 使用 `Lookfeel\AppendAutomate\Database\Eloquent\Model` 替换 `Illuminate\Database\Eloquent\Model`

[](#使用-lookfeelappendautomatedatabaseeloquentmodel-替换-illuminatedatabaseeloquentmodel)

只需将 Model 继承 `Lookfeel\AppendAutomate\Database\Eloquent\Model` 即可. `Lookfeel\AppendAutomate\Database\Eloquent\Model` 继承自 `Eloquent` 。

### 使用 `Lookfeel\AppendAutomate\AppendAutomateTrait`

[](#使用-lookfeelappendautomateappendautomatetrait)

如果由于某些原因不能继承 `Lookfeel\AppendAutomation\Database\Model`，那么您可以在已有 Model 中 `use Lookfeel\AppendAutomation\AppendAutomateTrait`。

#### 相关文章:

[](#相关文章)

单元测试
----

[](#单元测试)

```
$ composer install --dev
```

```
$ vendor/bin/phpunit
```

License
-------

[](#license)

\*\*Laravel Eloquent Append Automation \*\* is licensed under the [MIT License](http://opensource.org/licenses/MIT).

###  Health Score

32

—

LowBetter than 69% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity26

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity60

Established project with proven stability

 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 ~122 days

Recently: every ~194 days

Total

8

Last Release

1720d ago

### Community

Maintainers

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

---

Top Contributors

[![terranc](https://avatars.githubusercontent.com/u/224353?v=4)](https://github.com/terranc "terranc (27 commits)")

---

Tags

laravellaravel accessorslaravel appends

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/lookfeel-laravel-eloquent-append-automate/health.svg)

```
[![Health](https://phpackages.com/badges/lookfeel-laravel-eloquent-append-automate/health.svg)](https://phpackages.com/packages/lookfeel-laravel-eloquent-append-automate)
```

###  Alternatives

[mike-bronner/laravel-model-caching

Automatic caching for Eloquent models.

2.4k161.4k2](/packages/mike-bronner-laravel-model-caching)[laravel/ai

The official AI SDK for Laravel.

1.1k4.6M327](/packages/laravel-ai)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

265.2k](/packages/aedart-athenaeum)[propaganistas/laravel-disposable-email

Disposable email validator

6023.2M7](/packages/propaganistas-laravel-disposable-email)[forjedio/inertia-table

Backend-driven dynamic tables for Laravel + Inertia.js

272.0k](/packages/forjedio-inertia-table)[flarum/core

Delightfully simple forum software.

211.5M2.5k](/packages/flarum-core)

PHPackages © 2026

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