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

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

waad/laravel-model-metadata
===========================

A robust Laravel package for handling metadata with JSON casting, custom relation names, and advanced querying capabilities.

v3.0.1(2mo ago)823.1k↓39%3MITPHPPHP ^8.0CI passing

Since Jan 3Pushed 1mo ago3 watchersCompare

[ Source](https://github.com/waadmawlood/laravel-model-metadata)[ Packagist](https://packagist.org/packages/waad/laravel-model-metadata)[ RSS](/packages/waad-laravel-model-metadata/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (9)Dependencies (8)Versions (12)Used By (0)

[![Laravel Model Metadata](lmm.jpg)](lmm.jpg)

Laravel Model Metadata
======================

[](#laravel-model-metadata)

Laravel Model Metadata is a package designed to manage metadata with JSON support for multiple data types. It allows you to easily attach, manage, and query metadata on your Laravel models using the `HasManyMetadata` or `HasOneMetadata` traits.

📚 Documentation
===============

[](#-documentation)

For detailed documentation, including usage examples and best practices, please refer to the [Documentation](https://waad-mawlood.gitbook.io/model-metadata).

✨ Requirements
==============

[](#-requirements)

- PHP 8.0 or higher
- Laravel framework 9.30.1 or higher
- JSON extension enabled

💼 Installation
==============

[](#-installation)

1. Install the package using Composer:

    ```
    composer require waad/laravel-model-metadata
    ```
2. (Optional) Publish the config file first:

    ```
    php artisan vendor:publish --tag=metadata-config
    ```
3. (Recommended) Clear the configuration cache to ensure new config is loaded:

    ```
    php artisan config:clear
    ```
4. Publish the migration files:

    ```
    php artisan vendor:publish --tag=metadata-migrations
    ```
5. Run the migrations:

    ```
    php artisan migrate
    ```

⚙️ Configuration
================

[](#️-configuration)

You can customize the metadata table name, model, and caching behavior by editing the published config file at `config/model-metadata.php`:

```
return [
    'table' => 'model_metadata',
    'model' => Waad\Metadata\Models\Metadata::class,

    'cache' => [
        'enabled' => env('MODEL_METADATA_CACHE_ENABLED', false),
        'ttl'     => env('MODEL_METADATA_CACHE_TTL', 3600),
        'store'   => env('MODEL_METADATA_CACHE_STORE', null),
        'prefix'  => env('MODEL_METADATA_CACHE_PREFIX', 'model_metadata'),
    ],
];
```

🎈 Usage
=======

[](#-usage)

🔥 HasOneMetadata Trait
----------------------

[](#-hasonemetadata-trait)

Add the HasOneMetadata trait to your model to enable a single metadata record:

```
use Waad\Metadata\Traits\HasOneMetadata;

class Company extends Model
{
    use HasOneMetadata;  // createMetadata(['key' => 'value', 'another_key' => 'another_value']);

// Create metadata with collection
$company->createMetadata(collect(['key' => 'value']));

// Update existing metadata
$company->updateMetadata(['new_key' => 'new_value']);

// Delete the metadata
$company->deleteMetadata();

// Get metadata as array
$metadata = $company->getMetadata();

// Get metadata as collection
$metadataCollection = $company->getMetadataCollection();
```

---

🔥 HasManyMetadata Trait
-----------------------

[](#-hasmanymetadata-trait)

Add the HasManyMetadata trait to your model to enable multiple metadata records:

```
use Waad\Metadata\Traits\HasManyMetadata;

class Post extends Model
{
    use HasManyMetadata;  // createMetadata(['key1' => 'value1', 'key2' => 'value2']);
$post->createMetadata(collect(['key1' => 'value1', 'key2' => 'value2']));

// Update metadata by ID
$post->updateMetadata('{metadata_id}', ['new_key' => 'new_value']);

// Delete metadata by ID
$post->deleteMetadata('{metadata_id}');

// Get all metadata objects
$metadata = $post->metadata;
// or
$metadata = $post->metadata()->get();

// Get metadata by ID
$metadata = $post->getMetadataById('metadata_id');

// Get all metadata column pluck as array
$allMetadata = $post->getMetadata();

// Get all metadata column pluck as collection
$metadataCollection = $post->getMetadataCollection();

// Search in metadata
$searchResults = $post->searchMetadata('search_term');
```

---

### 🗄️ Cache

[](#️-cache)

The package includes an optional caching layer to reduce database queries. Cache is **disabled by default** and can be enabled in the config:

You can configure cache settings either in `config/model-metadata.php` or override them via your `.env` file.

Config Key / Env VariableTypeDefaultDescription`cache.enabled` / `MODEL_METADATA_CACHE_ENABLED``bool``false`Enable or disable metadata caching`cache.ttl` / `MODEL_METADATA_CACHE_TTL``int``3600`Cache time-to-live in seconds`cache.store` / `MODEL_METADATA_CACHE_STORE``string|null``null` (empty)Cache store to use (`null` = default Laravel cache driver)`cache.prefix` / `MODEL_METADATA_CACHE_PREFIX``string``model_metadata`Prefix for all metadata cache keysFor example, to enable cache and customize settings, add to `.env`:

```
MODEL_METADATA_CACHE_ENABLED=true
MODEL_METADATA_CACHE_TTL=3600
MODEL_METADATA_CACHE_STORE=redis
MODEL_METADATA_CACHE_PREFIX=model_metadata
```

When caching is enabled:

- **Read** operations (`getMetadata`, `getMetadataById`, `getMetadataCollection`) are automatically cached.
- **Write** operations (`create`, `update`, `delete`, `forget`, `sync`) automatically invalidate the cache.
- You can manually clear the cache for a specific model using `clearMetadataCache()`:

```
$company->clearMetadataCache();
$post->clearMetadataCache();
```

- You can check if caching is active:

```
$company->metadataCacheIsEnabled(); // bool
```

---

🧪 Testing
=========

[](#-testing)

To run the tests for development, use the following command:

```
composer test
```

👨‍💻 Contributors
================

[](#‍-contributors)

- **Waad Mawlood**
    - Email: [waad\_mawlood@outlook.com](mailto:waad_mawlood@outlook.com)
    - Role: Developer

📝 License
=========

[](#-license)

This package is open-sourced software licensed under the [MIT license](LICENSE).

###  Health Score

50

—

FairBetter than 96% of packages

Maintenance89

Actively maintained with recent releases

Popularity36

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity50

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

Recently: every ~87 days

Total

11

Last Release

61d ago

Major Versions

1.x-dev → v2.0.02025-01-29

v2.2.1 → v3.0.02026-03-16

PHP version history (2 changes)1.0.0PHP ^8.1

v2.0.0PHP ^8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/44348636?v=4)[Waad Mawlood](/maintainers/waadmawlood)[@waadmawlood](https://github.com/waadmawlood)

---

Top Contributors

[![waadmawlood](https://avatars.githubusercontent.com/u/44348636?v=4)](https://github.com/waadmawlood "waadmawlood (51 commits)")

---

Tags

jsonlaravelmetadatapackagejsonlaraveldatabasemodeleloquentmetadataFlexibleschema-less

###  Code Quality

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/waad-laravel-model-metadata/health.svg)

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

###  Alternatives

[designmynight/laravel-elasticsearch

Use Elasticsearch as a database in Laravel to retrieve Eloquent models and perform aggregations.

3038.6k](/packages/designmynight-laravel-elasticsearch)

PHPackages © 2026

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