PHPackages                             a1dbox/laravel-model-accessor-builder - 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. a1dbox/laravel-model-accessor-builder

ActiveLibrary

a1dbox/laravel-model-accessor-builder
=====================================

You can build query on model accessor. Sort or filter by accessor, and at the same time it's a regular model accessor

v1.0.3(3y ago)310MITPHPPHP ^7.4|^8.0

Since Jul 10Pushed 3y ago1 watchersCompare

[ Source](https://github.com/A1DBox/laravel-model-accessor-builder)[ Packagist](https://packagist.org/packages/a1dbox/laravel-model-accessor-builder)[ Docs](https://github.com/A1DBox/laravel-model-accessor-builder)[ RSS](/packages/a1dbox-laravel-model-accessor-builder/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (4)Dependencies (6)Versions (6)Used By (0)

Laravel Model Accessor Builder
==============================

[](#laravel-model-accessor-builder)

[![Latest Version on Packagist](https://camo.githubusercontent.com/3b35df8578550c2303144fb51de4e482527e42088f084883f3ffa6076de2e90c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f613164626f782f6c61726176656c2d6d6f64656c2d6163636573736f722d6275696c6465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/a1dbox/laravel-model-accessor-builder)[![Total Downloads](https://camo.githubusercontent.com/534ef87f0289637145ee69aef98448aee72f0a0977d8dc4d4d44759baaae4291/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f613164626f782f6c61726176656c2d6d6f64656c2d6163636573736f722d6275696c6465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/a1dbox/laravel-model-accessor-builder)

### You can build query on model accessor. Sort or filter by accessor, and at the same time it's a regular working accessor

[](#you-can-build-query-on-model-accessor-sort-or-filter-by-accessor-and-at-the-same-time-its-a-regular-working-accessor)

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require a1dbox/laravel-model-accessor-builder
```

Usage
-----

[](#usage)

Use the `HasAccessorBuilder` trait in your model to provide work of accessor builder:

```
use A1DBox\Laravel\ModelAccessorBuilder\Concerns\HasAccessorBuilder;

class User extends Model
{
    use HasAccessorBuilder;
}
```

Create Accessor for attribute

###### *Laravel 8.x accessor defining style*

[](#laravel-8x-accessor-defining-style)

```
class User extends Model
{
    use HasAccessorBuilder;

    public function getFullNameAttribute()
    {
        return AccessorBuilder::make(
            fn (AccessorBuilder\BlueprintCabinet $cabinet) => $cabinet->trim(
                $cabinet->concat(
                    $cabinet->col('name'),
                    $cabinet->str(' '),
                    $cabinet->col('last_name'),
                )
            ),
        );
    }
}
```

As example, code above will do same as this one, when resolving accessor value:

```
return trim($this->name . ' ' . $this->last_name);
```

### Example #1

[](#example-1)

Here, the `full_name` attribute contained in model `$attributes` after query And when using accessor `->full_name`, the value will be taken from `$attributes`

```
$user = User::query()
    ->withAccessor('full_name')
    ->find(1);

echo $user->full_name; //John Doe
```

SQL Query executed:

```
SELECT
    *,
    trim(concat(name, ' ', last_name)) AS full_name
FROM users WHERE id = 1
```

### Example #2

[](#example-2)

Here, the `full_name` attribute NOT contained in `$attributes` variable of model, and when using accessor `$user->full_name`, the value will be built from model `$attributes`

```
$user = User::find(1);

echo $user->full_name; //John Doe
```

SQL Query executed:

```
SELECT * FROM users WHERE id = 1
```

### Example #3

[](#example-3)

Get all users ordered by `full_name`

```
$users = User::query()
    ->withAccessor('full_name')
    ->orderBy('full_name')
    ->get();
```

### Example #4

[](#example-4)

Filter users by `full_name`

```
$users = User::query()
    ->withAccessor('full_name')
    ->where('full_name', 'John Doe')
    ->get();
```

### You can pass array to `withAccessor` method

[](#you-can-pass-array-to-withaccessor-method)

```
$users = User::query()
    ->withAccessor(['full_name', 'full_address'])
    ->get();
```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](https://github.com/A1DBox/.github/blob/main/CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [A1DBox](https://github.com/A1DBox)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity56

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

Total

4

Last Release

1362d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4e216f1586ff7ac4fe7ebaaa19e0999e1bae0f5ae0b1cfe16eec82a56af1c233?d=identicon)[A1DBox](/maintainers/A1DBox)

---

Top Contributors

[![A1DBox](https://avatars.githubusercontent.com/u/108633963?v=4)](https://github.com/A1DBox "A1DBox (18 commits)")

---

Tags

laravelA1DBoxmodel accessorfilter accessororder accessor

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/a1dbox-laravel-model-accessor-builder/health.svg)

```
[![Health](https://phpackages.com/badges/a1dbox-laravel-model-accessor-builder/health.svg)](https://phpackages.com/packages/a1dbox-laravel-model-accessor-builder)
```

###  Alternatives

[spatie/laravel-permission

Permission handling for Laravel 12 and up

12.9k89.8M1.0k](/packages/spatie-laravel-permission)[spatie/laravel-activitylog

A very simple activity logger to monitor the users of your website or application

5.8k45.4M309](/packages/spatie-laravel-activitylog)[spatie/laravel-health

Monitor the health of a Laravel application

85810.0M83](/packages/spatie-laravel-health)[dyrynda/laravel-model-uuid

This package allows you to easily work with UUIDs in your Laravel models.

4802.8M8](/packages/dyrynda-laravel-model-uuid)[clickbar/laravel-magellan

This package provides functionality for working with the postgis extension in Laravel.

423715.4k1](/packages/clickbar-laravel-magellan)[spatie/laravel-model-info

Get information about the models in your Laravel app

182322.8k12](/packages/spatie-laravel-model-info)

PHPackages © 2026

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