Download the PHP package waad/laravel-model-metadata without Composer
On this page you can find all versions of the php package waad/laravel-model-metadata. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package 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
For detailed documentation, including usage examples and best practices, please refer to the Documentation.
โจ Requirements
- PHP 8.0 or higher
- Laravel framework 9.30.1 or higher
- JSON extension enabled
๐ผ Installation
-
Install the package using Composer:
-
(Optional) Publish the config file first:
-
(Recommended) Clear the configuration cache to ensure new config is loaded:
-
Publish the migration files:
- Run the migrations:
โ๏ธ Configuration
You can customize the metadata table name, model, and caching behavior by editing the published config file at config/model-metadata.php:
๐ Usage
๐ฅ HasOneMetadata Trait
Add the HasOneMetadata trait to your model to enable a single metadata record:
Some methods:
๐ฅ HasManyMetadata Trait
Add the HasManyMetadata trait to your model to enable multiple metadata records:
see Configuration Append Id for more details
Some methods:
๐๏ธ 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 Variable | Type | Default | Description |
|---|---|---|---|
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 keys |
For example, to enable cache and customize settings, add to .env:
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(): - You can check if caching is active:
๐งช Testing
To run the tests for development, use the following command:
๐จโ๐ป Contributors
- Waad Mawlood
- Email: [email protected]
- Role: Developer
๐ License
This package is open-sourced software licensed under the MIT license.
All versions of laravel-model-metadata with dependencies
ext-json Version *
laravel/framework Version ^9.30.1|^10.0|^11.0|^12.0|^13.0