PHPackages                             paulhenri-l/laravel-dynamic-attributes - 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. [Database &amp; ORM](/categories/database)
4. /
5. paulhenri-l/laravel-dynamic-attributes

ActiveLibrary[Database &amp; ORM](/categories/database)

paulhenri-l/laravel-dynamic-attributes
======================================

Dynamically add attributes to your eloquent models

3.0.0(5y ago)36.1k1MITPHPPHP ^7.3

Since Sep 1Pushed 5y agoCompare

[ Source](https://github.com/paulhenri-l/laravel-dynamic-attributes)[ Packagist](https://packagist.org/packages/paulhenri-l/laravel-dynamic-attributes)[ RSS](/packages/paulhenri-l-laravel-dynamic-attributes/feed)WikiDiscussions master Synced 1mo ago

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

Laravel Dynamic Attributes
==========================

[](#laravel-dynamic-attributes)

[![Tests](https://github.com/paulhenri-l/laravel-dynamic-attributes/workflows/Tests/badge.svg)](https://github.com/paulhenri-l/laravel-dynamic-attributes/workflows/Tests/badge.svg)[![License: MIT](https://camo.githubusercontent.com/08cef40a9105b6526ca22088bc514fbfdbc9aac1ddbf8d4e6c750e3a88a44dca/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d626c75652e737667)](LICENSE)

Allow you to dynamically add attributes to your eloquent models at runtime.

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

[](#installation)

```
composer require paulhenri-l/laravel-dynamic-attributes

```

Usage
-----

[](#usage)

You'll first need to add the `HasDynamicAttributesTrait` to your model.

```
class Member extends Illuminate\Database\Eloquent\Model
{
    use PaulhenriL\LaravelDynamicAttributes\HasDynamicAttributes;
}
```

Then you can register dynamic fields from your constructor or any other place that will get called at runtime.

A good place for that is from the initialize method of a trait.

```
class Member extends Illuminate\Database\Eloquent\Model
{
    use PaulhenriL\LaravelDynamicAttributes\HasDynamicAttributes;

    public function __construct(array $attributes = [])
    {
        parent::__construct($attributes);

        $this->registerDynamicAttribute(
            'my_dynamic_attribute',
            function ($key) {
                return "Trying to get {$key}";
            },
            function ($key, $value) {
                echo "Setting {$key}";
            }
        );
    }
}
```

You can now set and get from your dynamic attribute:

```
$member = new Member();
$member->my_dynamic_attribute = 'Hello';
$member->my_dynamuc_attribute;

```

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

[](#contributing)

If you have any questions on how to use this library feel free to open an issue.

If you think that the documentation or the code could be improved in any way open a PR and I'll happily review it!

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity51

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

Total

3

Last Release

2023d ago

Major Versions

1.0.0 → 2.0.02020-09-02

2.0.0 → 3.0.02020-10-27

PHP version history (2 changes)1.0.0PHP ^7.2.5

3.0.0PHP ^7.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/dadbbf7b24bb9ee393f7a03b8c6c611e3f922096be33ac881e4641f744d12eb4?d=identicon)[paulhenri-l](/maintainers/paulhenri-l)

---

Top Contributors

[![paulhenri-l](https://avatars.githubusercontent.com/u/25308170?v=4)](https://github.com/paulhenri-l "paulhenri-l (7 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/paulhenri-l-laravel-dynamic-attributes/health.svg)

```
[![Health](https://phpackages.com/badges/paulhenri-l-laravel-dynamic-attributes/health.svg)](https://phpackages.com/packages/paulhenri-l-laravel-dynamic-attributes)
```

###  Alternatives

[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k7.2M71](/packages/mongodb-laravel-mongodb)[owen-it/laravel-auditing

Audit changes of your Eloquent models in Laravel

3.4k33.0M95](/packages/owen-it-laravel-auditing)[dyrynda/laravel-cascade-soft-deletes

Cascading deletes for Eloquent models that implement soft deletes

1.2k3.1M5](/packages/dyrynda-laravel-cascade-soft-deletes)[tightenco/parental

A simple eloquent trait that allows relationships to be accessed through child models.

1.5k1.8M5](/packages/tightenco-parental)[watson/validating

Eloquent model validating trait.

9723.3M47](/packages/watson-validating)[cybercog/laravel-ban

Laravel Ban simplify blocking and banning Eloquent models.

1.1k651.8k11](/packages/cybercog-laravel-ban)

PHPackages © 2026

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