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

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

nncodes/laravel-meta-attributes
===============================

Add meta attributes to Eloquent models

v2.1.1(4y ago)447241MITPHPPHP ^7.2.5|^7.3|^8.0

Since Dec 15Pushed 4y ago1 watchersCompare

[ Source](https://github.com/99codes/laravel-meta-attributes)[ Packagist](https://packagist.org/packages/nncodes/laravel-meta-attributes)[ Docs](https://github.com/99codes/laravel-meta-attributes)[ RSS](/packages/nncodes-laravel-meta-attributes/feed)WikiDiscussions v2 Synced 1mo ago

READMEChangelog (7)Dependencies (3)Versions (9)Used By (1)

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

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity64

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

Recently: every ~38 days

Total

8

Last Release

1810d ago

Major Versions

v1.0.1 → v2.02020-12-26

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1036401?v=4)[Leonardo Poletto](/maintainers/leopoletto)[@leopoletto](https://github.com/leopoletto)

---

Top Contributors

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

---

Tags

custom-propertieseloquent-modelslaravel-packagemeta-attributesnncodeslaravel-meta-attributes

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[spatie/laravel-backup

A Laravel package to backup your application

6.0k21.8M191](/packages/spatie-laravel-backup)[illuminate/database

The Illuminate Database package.

2.8k52.4M9.4k](/packages/illuminate-database)[kreait/laravel-firebase

A Laravel package for the Firebase PHP Admin SDK

1.3k16.5M42](/packages/kreait-laravel-firebase)[bavix/laravel-wallet

It's easy to work with a virtual wallet.

1.3k1.1M11](/packages/bavix-laravel-wallet)[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)

PHPackages © 2026

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