Download the PHP package miladev/lara-meta without Composer
On this page you can find all versions of the php package miladev/lara-meta. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download miladev/lara-meta
More information about miladev/lara-meta
Files in miladev/lara-meta
Package lara-meta
Short Description Save meta with any model.
License MIT
Homepage https://github.com/miladev95/lara-meta
Informations about the package lara-meta
Laravel Meta
Save metadata (key, value) with any model.
Sometimes, we may need to store few extra information for some objects. In some situation, it's not good solution to add new columns. This package can solve those issues.
The package will create a table in database named laravel_metas with key, value and metable column.
However, table name can be changed by updating table_name in config/meta.php.
N.B: After changing table_name, you need to delete the previous table (if exists) from DB and delete the create_meta_table row from migrations table.
Then re-run the php artisan migrate command again.
Installation
You can install the package via composer:
If you are using Laravel Package Auto-Discovery, you don't need you to manually add the ServiceProvider.
Without auto-discovery:
If you don't use auto-discovery, add the below ServiceProvider to the $providers array in config/app.php file.
If you want to change the meta table name, then first publish the config file.
Then, update the table_name value in config/meta.php.
Then you can run migration command to create database table.
Usage
Add Miladev\LaravelMeta\Metable trait to models where you need.
Then you can access like below:
Typed Meta Values
Define a per-key cast on your model to automatically cast values on write and read. Supported casts: string (default), int/integer, float/double, bool/boolean, json, date, datetime.
Roadmap
Ideas and planned features for future versions. Contributions are welcome!
- [x] Typed meta values — cast values to
int,float,bool,json,date, etc. via a per-key cast definition. - [ ] Array/object serialization — automatically serialize arrays and objects (JSON) on save and unserialize on read.
- [ ] Set multiple metas at once —
saveManyMeta(['key' => 'value', ...])/updateManyMeta()in a single transaction. - [ ] Get all metas as array/collection —
getAllMetas(): arrayreturning a key/value map. - [ ] Sync metas —
syncMetas(array $metas)that creates, updates, and deletes keys to match the given array (like Laravel'ssync()). - [ ] Has-meta scopes —
scopeWhereHasMeta($query, $key)andscopeWhereMeta($query, $key, $value)to filter models by meta existence/value. - [x] Meta value casting per model — override casts on the model, e.g.
protected $metaCasts = ['views' => 'int'];. - [ ] Numeric operators in scopes —
whereMetaGreaterThan(),whereMetaLessThan(),whereMetaIn(),whereMetaBetween(),whereMetaLike(). - [ ] Meta encryption — transparently encrypt/decrypt sensitive meta values (e.g.
encryptedcast). - [ ] Automatic model cleanup — delete related metas automatically when the metable model is deleted (cascade via model events or FK constraint).
- [ ] Global meta helper —
meta($model, 'key')andmeta_set($model, 'key', 'value')helper functions. - [ ] Artisan commands —
php artisan meta:set,meta:get,meta:delete,meta:listfor CLI inspection and management. - [ ] Tagged/grouped metas — an optional
groupcolumn so metas can be organized and fetched by group. - [ ] Meta with expiration — optional
expires_atcolumn and auto-cleanup of expired metas. - [ ] Revision/history tracking — keep a history of meta changes with old/new values, actor, and timestamps.
- [ ] Caching layer — cache loaded metas per model to avoid repeated queries, with automatic invalidation on write.
- [ ] Import/export — export all metas of a model (or the whole table) to JSON/CSV and re-import them.
- [ ] Counter metas —
incrementMeta($key, $amount)/decrementMeta($key, $amount)with atomic DB updates. - [ ] Batch operations — bulk set/get metas for collections of models, avoiding N+1 queries.
- [ ] Laravel Nova / Filament support — official fields/packages to view and edit metas from the admin panels.
Contribute
If you want to contribute, open a pull request by following Laravel contribution guide.
License
The MIT License (MIT). Please see License File for more information.
All versions of lara-meta with dependencies
illuminate/support Version ^7|^8|^9
illuminate/database Version ^7|^8|^9