PHPackages                             igorwanbarros/custom-accessor-and-mutator - 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. igorwanbarros/custom-accessor-and-mutator

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

igorwanbarros/custom-accessor-and-mutator
=========================================

to set attributes laravel model (accessors and mutators) without creating methods

v1.0.2(9y ago)06201MITPHP

Since Jun 12Pushed 9y ago1 watchersCompare

[ Source](https://github.com/igorwanbarros/custom-accessor-and-mutator)[ Packagist](https://packagist.org/packages/igorwanbarros/custom-accessor-and-mutator)[ RSS](/packages/igorwanbarros-custom-accessor-and-mutator/feed)WikiDiscussions master Synced today

READMEChangelog (2)Dependencies (1)Versions (4)Used By (0)

\#Custom Accessors and Mutators

> # Accessors e Mutators Personalizados
>
> [](#accessors-e-mutators-personalizados)

The *CustomAccessorsAndMutators* is a package to optimize the creation of accessor and mutator laravel. The focus is to set the accessors and mutators through an array informing the attribute as key and the method as value.

> A *CustomAccessorsAndMutators* é um pacote para otimizar a criação de accessor e mutator laravel. O foco é setar os accessors e mutators através de um array informando o atributo como chave e o metodo como valor.

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

[](#installation)

> ## Instalação
>
> [](#instalação)

### Composer

[](#composer)

If you already use Composer (which is highly recommended), add the dependency under the policy *"require"* your *composer.json*:

> Se você já utiliza o Composer (o que é extremamente recomendado), adicione a dependência abaixo à diretiva *"require"* do seu *composer.json*:

```
    require : {
            "laravel/framework": "5.1.*",
            "igorwanbarros/custom-accessor-and-mutator": "v1.*"
        }
```

Usage
-----

[](#usage)

> ## Uso
>
> [](#uso)

The package uses the trait *CustomAccessorsAndMutators* to set the attributes, just add it in their class, as shown below:

> O pacote utiliza a trait *CustomAccessorsAndMutators* para setar os atributos, para isso basta adiciona-la em suas classes, conforme mostrado abaixo:

```
use Illuminate\Database\Eloquent\Model;
use Igorwanbarros\CustomAccessorAndMutator\CustomAccessorsAndMutators;

class Order extends Model
{
    use CustomAccessorsAndMutators;

    protected $table = 'order';

    protected $customAccessors = [
        //attribute name you model   => your default method for treating this type of data
        'you_attribute_name'         => '_yourMethodGet',
        'you_other_attribute_name'   => '_yourMethodGet',
    ];

    protected $customMutators = [
        'you_atribute_name'         => '_yourMethodGet',
        'you_other_atribute_name'   => '_yourMethodGet',
    ];

    protected function _youtMethodGet($value)
    {
        //you logic here
        return $value;
    }

    protected function _youtMethodSet($value)
    {
        //you logic here
        return $value;
    }
}
```

Or, in your Model class base:

> Ou, em sua class Model base:

```
class ModelBase extends Model
{
    use CustomAccessorsAndMutators
}
```

And in other models add only the fields and their respective methods:

> E nos demais models adicionar apenas os campos e seus respectivos métodos:

```
class Order extends Model
{
    protected $table = 'order';

    protected $customAccessors = [
        'you_attribute_name'    => '_yourMethodGet',
    ];

    protected $customMutators = [
        'you_attribute_name'    => '_yourMethodGet',
    ];

    protected function _youtMethodGet($value)
    {
        //you logic here
        return $value;
    }

    protected function _youtMethodSet($value)
    {
        //you logic here
        return $value;
    }
}
```

### Adding via Class

[](#adding-via-class)

> ### Adicionando via Class
>
> [](#adicionando-via-class)

You can also implement the FormatAccessorsAndMutator class to define your formatting logic (for certain types of data for example) and tells you there as shown below:

> Você pode também implementar a classe *FormatAccessorsAndMutator* para definir sua lógica de formatação (para determinados tipos de dados por exemplo) e informa-lá conforme é mostrado abaixo:

```
namespace App\FormatAccessorsAndMutators;

use Igorwanbarros\CustomAccessorAndMutator\FormatAccessorAndMutator;

class MoneyFormatAccessorsAndMutators implements FormatAccessorAndMutator
{
    public static function get($value)
    {
        //you logic here
        return $value;
    }

    public static function set($value)
    {
        //you logic here
        return $value;
    }
}
```

Already in its Model class you can set as follows:

> Já em sua classe Model você pode definir da seguinte forma:

```
use Illuminate\Database\Eloquent\Model;
use Igorwanbarros\CustomAccessorAndMutator\CustomAccessorsAndMutators;
use App\FormatAccessorsAndMutators\MoneyFormatAccessorsAndMutators;

class Order extends Model
{
    use CustomAccessorsAndMutators;

    protected $table = 'order';

    protected $customAccessors = [
        'you_attribute_name'         => MoneyFormatAccessorsAndMutators::class,
        'you_other_attribute_name'   => MoneyFormatAccessorsAndMutators::class,
    ];

    protected $customMutators = [
        'you_atribute_name'         => MoneyFormatAccessorsAndMutators::class,
        'you_other_atribute_name'   => MoneyFormatAccessorsAndMutators::class,
    ];

}
```

Licence
-------

[](#licence)

MIT Licence

###  Health Score

30

—

LowBetter than 67% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity65

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

Total

3

Last Release

3345d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0e6839e41ea7c6161252870275eef62e31bf4ed73775a10a8b9f3cda17e6ffcb?d=identicon)[igorwanbarros](/maintainers/igorwanbarros)

---

Top Contributors

[![igorwanbarros](https://avatars.githubusercontent.com/u/8918508?v=4)](https://github.com/igorwanbarros "igorwanbarros (9 commits)")

### Embed Badge

![Health badge](/badges/igorwanbarros-custom-accessor-and-mutator/health.svg)

```
[![Health](https://phpackages.com/badges/igorwanbarros-custom-accessor-and-mutator/health.svg)](https://phpackages.com/packages/igorwanbarros-custom-accessor-and-mutator)
```

###  Alternatives

[nickurt/laravel-akismet

Akismet for Laravel 11.x &amp; 12.x

98135.0k2](/packages/nickurt-laravel-akismet)[imanghafoori/laravel-anypass

A minimal yet powerful package to help you in development.

21421.2k](/packages/imanghafoori-laravel-anypass)[binshops/laravel-ticket

A simple ticketing system for Laravel 5.1 – 5.8 and 6.\* - 7.\* - 8.\* - 9.\* - 10.\* -which integrates smoothly with Laravel default users and auth system

261.0k](/packages/binshops-laravel-ticket)

PHPackages © 2026

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