jantinnerezo / laravel-model-meta
Requires
- php: ^7.2
- illuminate/support: ^5.5 || ^6.0 || ^7.0 || ^8.0
Requires (Dev)
- orchestra/testbench: ^3.0 || ^4.0 || ^5.0
- phpunit/phpunit: ^7.0 || ^8.0 || ^9.0
This package is auto-updated.
Last update: 2024-12-06 03:22:28 UTC
README
A very basic and simple metable trait that adds additional fields to your existing eloquent models. Main purpose for this package is the ability to add meta fields for MySQL versions lower than 5.7 without using MySQL JSON fields.
I used it personally for my projects that is hosted with MySQL version lower than 5.7. I recommend using other packages that supports MySQL JSON fields if your project's MySQL version is 5.7 only.
Installation
You can install the package via composer:
composer require jantinnerezo/laravel-model-meta
Usage
Create a migration that adds new field called "meta" to your existing table and then add the Metable trait to the model.
use Jantinnerezo\LaravelModelMeta\Metable; class YourModel extends Model { use Metable; }
Set meta
$yourModel = YourModel::find(1); $yourModel->setMeta( 'intro', // Key "Hey Jude, don't make it bad!" // Value );
Sync multiple meta
$yourModel = YourModel::find(1); $yourModel->syncMeta([ 'key1' => 'First key', 'key2' => 'Second key' ]);
Remove meta
$yourModel = YourModel::find(1); $yourModel->removeMeta('key');
Get single meta
$yourModel = YourModel::find(1); $yourModel->getMeta('key');
Get multiple meta
$yourModel = YourModel::find(1); $yourModel->getMetaOnly(['key1','key2']);
Get all meta
$yourModel = YourModel::find(1); $yourModel->getAllMeta();
Testing
composer test
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email erezojantinn@gmail.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.