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 2w 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

29

—

LowBetter than 57% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity53

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

2121d 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://avatars.githubusercontent.com/u/25308170?v=4)[Paul-Henri Leobon](/maintainers/paulhenri-l)[@paulhenri-l](https://github.com/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.1k8.9M110](/packages/mongodb-laravel-mongodb)[psalm/plugin-laravel

Psalm plugin for Laravel

3345.4M354](/packages/psalm-plugin-laravel)[pressbooks/pressbooks

Pressbooks is an open source book publishing tool built on a WordPress multisite platform. Pressbooks outputs books in multiple formats, including PDF, EPUB, web, and a variety of XML flavours, using a theming/templating system, driven by CSS.

45844.8k1](/packages/pressbooks-pressbooks)[flat3/lodata

OData v4.01 Producer for Laravel

100357.6k](/packages/flat3-lodata)[aimeos/laravel-nestedset

Nested Set Model for Laravel

3821.6k11](/packages/aimeos-laravel-nestedset)[aedart/athenaeum

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

265.2k](/packages/aedart-athenaeum)

PHPackages © 2026

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