PHPackages                             stanubusiness/laravel-meta-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. stanubusiness/laravel-meta-attributes

ActiveLibrary

stanubusiness/laravel-meta-attributes
=====================================

Pakcage forked from nncodes/laravel-meta-attributes. Add meta attributes to Eloquent models

2.1.5(11mo ago)03.5k↓34.6%MITPHPPHP ^7.2.5|^7.3|^8.0|^8.1|^8.2

Since Apr 15Pushed 11mo agoCompare

[ Source](https://github.com/StaNuBusiness/laravel-meta-attributes)[ Packagist](https://packagist.org/packages/stanubusiness/laravel-meta-attributes)[ Docs](https://github.com/99codes/laravel-meta-attributes)[ RSS](/packages/stanubusiness-laravel-meta-attributes/feed)WikiDiscussions v2 Synced today

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

Laravel Meta Attributes
=======================

[](#laravel-meta-attributes)

[![Latest Version on Packagist](https://camo.githubusercontent.com/97d4000b7f3aba782bca257bc728b9e62fd5120ff6237f0871d77e5c08aa845a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6e6e636f6465732f6c61726176656c2d6d6574612d617474726962757465732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/nncodes/laravel-meta-attributes)[![Total Downloads](https://camo.githubusercontent.com/885c8a22cd3ef7dd5471cb7fb2b3936d3347fad3507281d957492598f8b1d7d7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6e6e636f6465732f6c61726176656c2d6d6574612d617474726962757465732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/nncodes/laravel-meta-attributes)

Add meta attributes to Eloquent models

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

[](#installation)

You can install the package via composer:

```
composer require nncodes/laravel-meta-attributes
```

You need to publish and run the migration:

```
php artisan vendor:publish --provider="Nncodes\MetaAttributes\MetaAttributesServiceProvider" --tag="migrations"
php artisan migrate
```

Preparing your model
--------------------

[](#preparing-your-model)

To associate meta attributes with a model, the model must implement the following interface and trait:

```
namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Nncodes\MetaAttributes\Concerns\HasMetaAttributes;

class YourModel extends Model
{
    use HasMetaAttributes;
}
```

Usage
-----

[](#usage)

You can set meta attributes to your model like this:

```
$yourModel = YourModel::find(1);

/**
 * Store the meta value using type auto discover
 *
 * @note types: boolean, integer, double, string,
 * object, array, collection, date, datetime.
*/

$yourModel->setMeta($key)->value($value);

//For all other types you can specify using casting methods.

$yourModel->setMeta('departament')->asString('IT');

$yourModel->setMeta('salaryInteger')->asInteger(1489);

$yourModel->setMeta('salaryFloat')->asFloat(1489.909);

$yourModel->setMeta('salaryDecimal')->asDecimal(1489.9, $digitgs = 2);

$yourModel->setMeta('salaryDouble')->asDouble(1489.90);

$yourModel->setMeta('salaryPerSecond')->asReal(0.00001);

$yourModel->setMeta('favoriteColors')->asArray([
    'red', 'blue', 'yellow', 'white'
]);

$yourModel->setMeta('tastes')->asCollection([
	['name' => 'Coffee', 'type' => 'Beverage', 'rate' => 9],
  	['name' => 'Rice', 'type' => 'Food', 'rate' => 7],
]);

$yourModel->setMeta('skills')->asObject([
    'PHP' => 'Very Good',
    'Laravel' => 'Very Good',
    'MySQL' => 'Good'
]);

$yourModel->setMeta('isAdult')->asBoolean(true);

$yourModel->setMeta('nid')->asEncrypted('FL-104050');

$yourModel->setMeta('birthdate')->asDate(
    '1991-01-29',
    $format = 'Y-m-d H:i:s'
);

$yourModel->setMeta('lastLoginAt')->asDatetime(
    '2020-01-01 10:10:10',
    $format = 'Y-m-d H:i:s'
);

$yourModel->setMeta('createdAt')->asTimestamp($timestamp = time());
```

And your can get a meta attribute from your model:

```
$yourModel->getMeta($key); //Eloquent object
$yourModel->getMetaValue($key, $fallback = null); //Only the value
```

To get the collection of meta attributes from your from:

```
$yourModel->getMetas();
```

Or you can access all meta attributes as an object:

```
$yourModel->meta->birthdate;
$yourModel->meta->createdAt;
```

You can also check if the model already has a meta attribute:

```
$yourModel->hasMeta($key);
```

If you need to delete the meta attribute, it is simple:

```
$yourModel->forgeMeta($key);
```

Credits
-------

[](#credits)

- [Leonardo Poletto](https://github.com/leopoletto)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

36

—

LowBetter than 83% of packages

Maintenance51

Moderate activity, may be stable

Popularity23

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 83.3% 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 ~0 days

Total

2

Last Release

342d ago

### Community

Maintainers

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

---

Top Contributors

[![leopoletto](https://avatars.githubusercontent.com/u/1036401?v=4)](https://github.com/leopoletto "leopoletto (25 commits)")[![StaNuBusiness](https://avatars.githubusercontent.com/u/154808515?v=4)](https://github.com/StaNuBusiness "StaNuBusiness (5 commits)")

---

Tags

nncodeslaravel-meta-attributes

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/stanubusiness-laravel-meta-attributes/health.svg)

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

###  Alternatives

[illuminate/process

The Illuminate Process package.

44658.7k46](/packages/illuminate-process)

PHPackages © 2026

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