PHPackages                             whilesmart/eloquent-metadata - 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. whilesmart/eloquent-metadata

ActiveLibrary

whilesmart/eloquent-metadata
============================

Reusable metadata json column and helpers for Eloquent models

060PHPCI passing

Since Jun 14Pushed 2mo agoCompare

[ Source](https://github.com/whilesmartphp/eloquent-metadata)[ Packagist](https://packagist.org/packages/whilesmart/eloquent-metadata)[ RSS](/packages/whilesmart-eloquent-metadata/feed)WikiDiscussions dev Synced 1w ago

READMEChangelogDependenciesVersions (1)Used By (0)

Eloquent Metadata
=================

[](#eloquent-metadata)

A reusable `metadata` bag for Eloquent models: dot-notation get/set helpers, a query scope, and two interchangeable storage strategies. Use it to hold values that are unlikely or awkward as first-class table columns, keeping the core schema clean and extensible.

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

[](#installation)

```
composer require whilesmart/eloquent-metadata
```

The service provider is auto-discovered. Optionally publish the config:

```
php artisan vendor:publish --tag=metadata-config
```

Two storage strategies
----------------------

[](#two-storage-strategies)

StrategyWhere it storesWhen to use`column` (default)a json column on the model's own tableper-model bag, fewer joins, queries stay on the row`table`rows in one shared polymorphic `model_metadata` tableno schema change per model; one place for all metadataSet the default for the whole app in `config/metadata.php`, or override per model.

### Column strategy

[](#column-strategy)

Add the column in a migration with the Blueprint macro, then add the trait:

```
Schema::create('phases', function (Blueprint $table) {
    $table->id();
    $table->string('name');
    $table->metadata(); // nullable json column
    $table->timestamps();
});
```

```
use Whilesmart\Metadata\Traits\HasMetadata;

class Phase extends Model
{
    use HasMetadata; // uses config('metadata.strategy'), 'column' by default
}
```

### Table strategy

[](#table-strategy)

No column needed. The package ships the shared `model_metadata` table migration (disable with `register_table_migration => false`). Override the strategy on the model:

```
use Whilesmart\Metadata\Traits\HasMetadata;

class Agent extends Model
{
    use HasMetadata;

    protected $metadataStrategy = 'table';
}
```

To make `table` the app-wide default instead, set `'strategy' => 'table'` in the config.

Helpers (identical for both strategies)
---------------------------------------

[](#helpers-identical-for-both-strategies)

```
$model->setMeta('billing.rate', 120);
$model->getMeta('billing.rate');        // 120
$model->getMeta('missing', 'default');  // 'default'
$model->getMeta();                      // the whole array

Model::whereMeta('billing.rate', 120)->get();
```

### Persistence note

[](#persistence-note)

- **column**: `setMeta()` mutates the attribute; call `save()` to persist (like any Eloquent attribute).
- **table**: `setMeta()` writes the shared row immediately via `updateOrCreate`.

Configuration
-------------

[](#configuration)

`config/metadata.php`:

```
return [
    'strategy' => 'column',          // 'column' | 'table'
    'column' => 'metadata',          // column name for the column strategy
    'table' => 'model_metadata',     // shared table name for the table strategy
    'register_table_migration' => true,
];
```

License
-------

[](#license)

MIT

###  Health Score

22

—

LowBetter than 21% of packages

Maintenance56

Moderate activity, may be stable

Popularity12

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity12

Early-stage or recently created project

 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.

### Community

Maintainers

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

---

Top Contributors

[![nfebe](https://avatars.githubusercontent.com/u/14317775?v=4)](https://github.com/nfebe "nfebe (1 commits)")

### Embed Badge

![Health badge](/badges/whilesmart-eloquent-metadata/health.svg)

```
[![Health](https://phpackages.com/badges/whilesmart-eloquent-metadata/health.svg)](https://phpackages.com/packages/whilesmart-eloquent-metadata)
```

PHPackages © 2026

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