Laravel Packages

Manage Metadata on Laravel Eloquent Models with JSON Support

Published
Manage Metadata on Laravel Eloquent Models with JSON Support image

The Laravel Model Metadata package is designed to manage metadata in your Eloquent models with JSON support for multiple data types. With this package, you can easily attach, manage, and query your metadata:

use Waad\Metadata\Traits\HasManyMetadata;
 
class Post extends Model
{
use HasManyMetadata;
}
 
$post->createMetadata(['key' => 'value', 'another_key' => 'another_value']);
$post->updateMetadata('metadata_id', ['new_key' => 'new_value']);
$post->deleteMetadata('metadata_id');

This package also has convenience methods to retrieve metadata, whether your Model has one record or can have many metadata records:

// Operations for models with "has many" metadata
$metadata = $post->getMetadataById('metadata_id');
$allMetadata = $post->getMetadata();
$metadataCollection = $post->getMetadataCollection();
$searchResults = $post->searchMetadata('search_term');
 
// Operations for models with "has one" metadata
$metadata = $company->getMetadata();
$metadataCollection = $company->getMetadataCollection();

Main Features

  • Allow one model to have many metadata records
  • Allow one model to have one metadata record
  • Create, update, delete, and search metadata
  • JSON casting using the package's built-in trait
  • A polymorphic table design to attach metadata to any model

You can learn more about this package, get full installation instructions, and view the source code on GitHub.

Paul Redmond photo

Staff writer at Laravel News. Full stack web developer and author.

Sponsored

serpapi logo
SerpApi

The Web Search API for Your LLM and AI Applications

Visit SerpApi

The latest

View all →
Laravel Auditor Audits Your App With Your Own AI Agent image

Laravel Auditor Audits Your App With Your Own AI Agent

Read article
A simple form builder that stays out of your way image

A simple form builder that stays out of your way

Read article
Laravel AI: Trace Agent Runs With Lifecycle Events image

Laravel AI: Trace Agent Runs With Lifecycle Events

Read article
Laravel AI: Get Raw HTTP Responses and Rate Limits image

Laravel AI: Get Raw HTTP Responses and Rate Limits

Read article
Agent Run Observability in Laravel AI SDK 0.11 image

Agent Run Observability in Laravel AI SDK 0.11

Read article
Debounced Queued Event Listeners in Laravel image

Debounced Queued Event Listeners in Laravel

Read article