lao9s / modelmetabox
此包已弃用且不再维护。未建议替换包。
:description
dev-master
2019-04-11 11:23 UTC
Requires
Requires (Dev)
- mockery/mockery: ^1.1
- orchestra/testbench: ~3.0
- phpunit/phpunit: ~7.0
- sempro/phpunit-pretty-print: ^1.0
This package is auto-updated.
Last update: 2021-05-08 17:32:52 UTC
README
在不添加列到迁移文件的情况下,向 EloquentModel 添加额外的列(元框)
安装
通过 Composer
$ composer require lao9s/modelmetabox
用法
在要跟踪的模型上使用 ModelMetaBox 特性
use lao9s\ModelMetaBox\Traits\ModelMetaBoxTrait;
class Article extends Model
{
use ModelMetaBoxTrait;
...
}
发布配置文件。
php artisan vendor:publish --tag=ModelMetaBoxConfig
迁移
php artisan migrate
更改配置文件
// Override the delete method in the model to delete meta boxes before the model is deleted.
'override_the_delete_method' => true,
以下是代码示例
// Add/Update meta box to the article
$article->addMetaBox('author', 'Dima Botezatu');
// Support array data. Object or array data will be automatically converted to json.
// If you have another type of data, you can manually convert it into json by adding the third true parameter
$article->addMetaBox('images', ['image1.jpg', 'image2.jpg', 'image3.jpg']);
// Get meta box by specific key. $withValue parameter will return only value not the model object
$article->getMetaBox('author', $withValue = false)
// Also the meta box model have any methods: getValue, getKey or isJson
// Working only if you get metabox object model
$author = $article->getMetaBox('author')
$author->getValue();
$author->getKey();
$author->isJson();
// Get all meta boxes. $withValue parameter will return only values not the models object
$article->getAllMetaBoxes($withValue = false)
// Remove meta box
$article->removeMetaBox('author');
// Remove all meta boxes
$article->removeAllMetaBoxes();
致谢
许可证
MIT。请参阅许可证文件以获取更多信息。