PHPackages                             liam-wiltshire/laravel-model-meta - 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. liam-wiltshire/laravel-model-meta

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

liam-wiltshire/laravel-model-meta
=================================

Metadata support for Eloquent

1.0.0(2mo ago)246.9k↓34.1%6[2 PRs](https://github.com/liam-wiltshire/laravel-model-meta/pulls)MITPHPPHP ^8.2CI failing

Since Apr 18Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/liam-wiltshire/laravel-model-meta)[ Packagist](https://packagist.org/packages/liam-wiltshire/laravel-model-meta)[ RSS](/packages/liam-wiltshire-laravel-model-meta/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (8)Dependencies (10)Versions (10)Used By (0)

liam-wiltshire/laravel-model-meta
=================================

[](#liam-wiltshirelaravel-model-meta)

liam-wiltshire/laravel-model-meta is an extension to the default Laravel Eloquent model to add metadata to a model.

What MetaData?
==============

[](#what-metadata)

While Eloquent is very good at handling relational data, however not all data we deal with works like this. Without going as far as using a NoSQL solution such as Mongo, using mySQL to hold relational data, but with a JSON meta field is a potential solution.

liam-wiltshire/laravel-model-meta allows you to use standard Eloquent getters and setters to add and remove metadata to your models. Any attributes that relate to a column in your database table will be handled as a standard attribute, but anything else will be added to the meta data.

This gives you great flexibility to have structured data where appropriate (for example an book will always have a title, author etc), but to then have other related, unstructured data (for example some books might have the number of pages, others might not)

When you are structuring your data, it's important to consider if you want to be able to query this data. Unless you use something like virtual columns at the DB level, this data isn't queryable - it's not designed to store the primary data for that record.

Example
=======

[](#example)

```
$book = new \App\Models\Book();

$book->forceFill(
[
    'title' => 'Laravel Quickstart Guide',
    'author_id' => 90,
    'publisher_id' => 5,
    'description' => 'This is an awesome book'
]
);

$book->save();

$book = \App\Models\Book::find(1);

//This is an actual field in the DB, so this will be set to that attribute
$book->title = 'Laravel Quickstart Guide, Second Edition';

//This isn't a field in the DB, and isn't a relationship etc, so will be stored in the meta field
$book->page_count = 200;

$test->save();
```

This code would generate a new `Test` model and save it to the DB. Assuming that `meta_subject` is not a column in our table, the `meta_subject` will automatically be added to the metadata:

```
root@localhost:[homestead]> SELECT id, title, meta FROM books;
+----+------------------------------------------+--------------------+
| id | title                                    | meta               |
+----+------------------------------------------+--------------------+
|  1 | Laravel Quickstart Guide, Second Edition | {"page_count":200} |
+----+------------------------------------------+--------------------+

```

Installation
============

[](#installation)

liam-wiltshire/laravel-model-meta is available as a composer package: `composer require liam-wiltshire/laravel-model-meta`

Once installed, use the `\LiamWiltshire\LaravelModelMeta\Concerns\HasMeta` trait in your model.

The database table behind the model will need a meta column adding - by default the trait assumes this will be called `meta`:

```
$table->json('meta')->nullable()->default(null);
```

If the name of your meta column is different, then add a `$metaDbField` property to your model containing the name of the field:

```
protected $metaDbField = 'metaData';
```

Migration &amp; Compatibility
=============================

[](#migration--compatibility)

Version Compatibility
---------------------

[](#version-compatibility)

### Current Version (v1.0+)

[](#current-version-v10)

**For Laravel 11 &amp; 12 with PHP 8.2+**

```
composer require liam-wiltshire/laravel-model-meta:^1.0
```

**Requirements:**

- PHP `^8.2`
- Laravel `^11.0|^12.0`
- PHPUnit `^10.0|^11.0` (dev)

### Legacy Version (v0.5.x)

[](#legacy-version-v05x)

**For Laravel 5.5-10 with PHP 7.1+**

```
composer require liam-wiltshire/laravel-model-meta:^0.5
```

**Requirements:**

- PHP `^7.1|^8.0`
- Laravel `^5.5|^6.0|^7.0|^8.0|^9.0|^10.0`
- PHPUnit `^7.0` (dev)

**Note:** If you're running an older version of Laravel or PHP, continue using v0.5.x. Version 1.0+ includes breaking changes related to minimum PHP and Laravel version requirements.

###  Health Score

57

—

FairBetter than 98% of packages

Maintenance84

Actively maintained with recent releases

Popularity34

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity78

Established project with proven stability

 Bus Factor1

Top contributor holds 50% 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 ~358 days

Recently: every ~483 days

Total

8

Last Release

80d ago

Major Versions

0.5.0 → 1.0.02026-02-27

PHP version history (2 changes)0.0.1PHP &gt;=7.1.0

1.0.0PHP ^8.2

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/10179637?v=4)[Liam Wiltshire](/maintainers/liam-wiltshire)[@liam-wiltshire](https://github.com/liam-wiltshire)

---

Top Contributors

[![liam-wiltshire](https://avatars.githubusercontent.com/u/10179637?v=4)](https://github.com/liam-wiltshire "liam-wiltshire (12 commits)")[![TebexTom](https://avatars.githubusercontent.com/u/185941963?v=4)](https://github.com/TebexTom "TebexTom (4 commits)")[![zmjafary](https://avatars.githubusercontent.com/u/30399030?v=4)](https://github.com/zmjafary "zmjafary (4 commits)")[![TebexOllie](https://avatars.githubusercontent.com/u/62796605?v=4)](https://github.com/TebexOllie "TebexOllie (3 commits)")[![haseebahmedswishtag](https://avatars.githubusercontent.com/u/158997541?v=4)](https://github.com/haseebahmedswishtag "haseebahmedswishtag (1 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/liam-wiltshire-laravel-model-meta/health.svg)

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

###  Alternatives

[owen-it/laravel-auditing

Audit changes of your Eloquent models in Laravel

3.4k33.0M95](/packages/owen-it-laravel-auditing)[staudenmeir/eloquent-json-relations

Laravel Eloquent relationships with JSON keys

1.1k5.8M24](/packages/staudenmeir-eloquent-json-relations)[bavix/laravel-wallet

It's easy to work with a virtual wallet.

1.3k1.1M11](/packages/bavix-laravel-wallet)[dragon-code/migrate-db

Easy data transfer from one database to another

15717.4k](/packages/dragon-code-migrate-db)[gearbox-solutions/eloquent-filemaker

A package for getting FileMaker records as Eloquent models in Laravel

6454.8k2](/packages/gearbox-solutions-eloquent-filemaker)[cybercog/laravel-ownership

Laravel Ownership simplify management of Eloquent model's owner.

9126.6k3](/packages/cybercog-laravel-ownership)

PHPackages © 2026

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