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 →
CPX: The Composer Package Executor for PHP image

CPX: The Composer Package Executor for PHP

Read article
Laravel AI SDK Adds Human-in-the-Loop Tool Approval image

Laravel AI SDK Adds Human-in-the-Loop Tool Approval

Read article
Pest 5 Released With Test Impact Analysis, Agent Verification, and Evals image

Pest 5 Released With Test Impact Analysis, Agent Verification, and Evals

Read article
Queue-SQL: Run Mass Deletes and Updates Across Parallel Queue Jobs image

Queue-SQL: Run Mass Deletes and Updates Across Parallel Queue Jobs

Read article
Blade Formatting in Laravel Pint image

Blade Formatting in Laravel Pint

Read article
Inertia DevTools Is Now on the Chrome Web Store image

Inertia DevTools Is Now on the Chrome Web Store

Read article