Manage Metadata on Laravel Eloquent Models with JSON Support
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. The post Manage Metadata on Laravel Eloquent Models with JSON Support appeared first on Laravel News. Join the Laravel Newsletter to get Laravel articles like this directly in your inbox.
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.
The post Manage Metadata on Laravel Eloquent Models with JSON Support appeared first on Laravel News.
Join the Laravel Newsletter to get all the latest Laravel articles like this directly in your inbox.
What's Your Reaction?