Download the PHP package digitalruby/meta-data without Composer
On this page you can find all versions of the php package digitalruby/meta-data. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download digitalruby/meta-data
More information about digitalruby/meta-data
Files in digitalruby/meta-data
Package meta-data
Short Description Adds a flexible key/value table to your Laravel models
License MIT
Informations about the package meta-data
DigitalRuby/MetaData
Adds a flexible key/value table to your Laravel models.
Why this package?
I often find myself needing to store extra bits of information across entities in my apps. This could be a github link, maybe a SEO title or a path to a file.
Instead of expanding my database with new fields across multiple entities, I often resort back to a simple key value table
that has a polymorphic relationship
to any entity.
This package provides you with that table and a trait
that you can add to your models to implement the functionality.
Installation
To install the package, use Composer:
After installing, you should run the migration to create the meta_data
table in your database:
This command creates the necessary table for storing meta data related to your models.
Usage
-
Add the Trait to Your Model:
First, include the
HasMetaData
trait in any Eloquent model you wish to associate meta data with. -
Setting Meta Data:
To add or update meta data for a model, use the
setMeta
method.key
: The meta data key.value
: The meta data value. Can be a string, array, or object. Arrays and objects are automatically encoded to JSON.
-
Getting Meta Data:
Retrieve a value with the
getMeta
method.Optionally, you can retrieve all meta data associated with the model:
-
Deleting Meta Data:
To remove a meta data entry, use
deleteMeta
.This will delete the meta data entry with the specified key.
-
Advanced Usage:
The
getMeta
method supports additional query modifications via a callback function, allowing for more complex queries.
Requirements
- PHP 8 or higher
- Laravel 10 or higher
Contributing
We welcome contributions! Please submit pull requests for bug fixes, features, or improvements.
License
The DigitalRuby/MetaData package is open-sourced software licensed under the MIT license.