sukohi/metaphor
Larablocks Analysis
sukohi/metaphor works with Laravel 5 (latest release 3.0.1, May 6, 2019), which reached end of life: no more fixes, even for security.
Recommendation checks
Not advisedNot advised: no release or commit in over 2 years.
- No release or commit in over 2 years
- Supports only Laravel 5, past end of life
- No release in the last 12 months (last: May 6, 2019)
- 0 downloads a month (needs 10,000)
- 1 GitHub star (needs 100)
State
Likely abandoned- No release or commit in over 2 years.
- Last stable release: May 6, 2019.
- No releases in the last 12 months.
- First released: Oct 10, 2015.
- 1 open issue on GitHub.
Data from Packagist and GitHub, checked by Larablocks on Nov 28, 2026.
| Install | |
|---|---|
composer require sukohi/metaphor |
|
| Latest Version: | 3.0.1 |
| Laravel: | 5 |
| License: | MIT |
| Last Updated: | May 6, 2019 |
| Links: | GitHub · Packagist |
Metaphor
A Laravel package that allows you to manage metadata. This package is maintained under Laravel 5.8.
Installation
Run the following command.
composer require sukohi/metaphor:3.*
Preparation
1. Trait
Set MetaphorTrait in your model as follows.
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Sukohi\Metaphor\MetaphorTrait;
class Item extends Model
{
use MetaphorTrait;
}
2. Migration
Just run the migration command.
Note: You do NOT need to make any migrations by yourself because this package already has it.
php artisan migrate
That's it!
Usage
Save
$item = \App\Item::find(1);
$item->meta->key_1 = 300;
$item->meta->key_2 = 'yyy';
$item->meta->key_3 = ['item_1x', 'item_2', 'item_3'];
$item->meta->key_4 = null;
$item->meta->save();
Note: $item->meta is an extended Collection of Laravel.
So you can use all of the methods as usual.
Delete
$item->meta->delete($key);
// or
$item->meta->deleteAll();
Check if a meta value exists
if($item->meta->has($key)) {
// has it!
}
About appending
If you'd like metadata to include in model data, set meta to $appends.
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Sukohi\Metaphor\MetaphorTrait;
class Item extends Model
{
use MetaphorTrait;
protected $appends = ['meta']; // <- here
}
Where clause
1. whereMeta
\App\Item::whereMeta('price', '500')->get();
\App\Item::whereMeta('price', 'LIKE', '%50%')->get();
\App\Item::orWhereMeta('price', '500')->get();
\App\Item::orWhereMeta('price', 'LIKE', '%50%')->get();
2. whereMetaIn
\App\Item::whereMetaIn('price', [300, 500])->get();
\App\Item::orWhereMetaIn('price', [300, 500])->get();
3. whereMetaNotIn
\App\Item::whereMetaNotIn('price', [300, 500])->get();
\App\Item::orWhereMetaNotIn('price', [300, 500])->get();
4. whereMetaNull
\App\Item::whereMetaNull('price')->get();
\App\Item::orWhereMetaNull('price')->get();
5. whereMetaNotNull
\App\Item::whereMetaNotNull('price')->get();
\App\Item::orWhereMetaNotNull('price')->get();
OrderByMeta
\App\Item::orderByMeta($key', 'asc')->get();
\App\Item::orderByMeta($key', 'desc')->get();
Note: This method uses FIELD(value, val1, val2, val3, ...) function in SQL.
It means if your DB system does not have the function, this feature is not available. MySQL has it, though.
License
This package is licensed under the MIT License.
Copyright 2019 Sukohi Kuhoh
Related Packages
Powerful PHP database abstraction layer (DBAL) with many features for database s...
Laravel Serializable Closure provides an easy and secure way to serialize closur...
Cli error handling for console/command-line PHP applications.
Version History
| Version | Released | Laravel | License |
|---|---|---|---|
| 3.0.1 | ~5.8.13 | MIT | |
| 3.0.0 | ~5.8.13 | MIT | |
| 2.0.8 | ~5.0 | MIT | |
| 2.0.7 | ~5.0 | MIT | |
| 2.0.6 | ~5.0 | MIT | |
| 2.0.5 | ~5.0 | MIT | |
| 2.0.4 | ~5.0 | MIT |