laraplug / attribute-module
v0.3.1
2018-03-09 15:02 UTC
Requires
- php: >=7.0.0
- composer/installers: ~1.0
- idavoll/core-module: ~3.0
Requires (Dev)
- orchestra/testbench: 3.5.*
- phpunit/phpunit: ~6.0
This package is not auto-updated.
Last update: 2024-09-29 05:27:42 UTC
README
Laraplug 属性
Laraplug 属性 是一个基于 AsgardCMS 平台的 EAV 电子商务模块。
已在 laraplug/product-module 中成功实现
目录
安装
-
通过 composer 安装包
composer require laraplug/attribute-module
-
通过 AsgardCMS 的模块命令执行迁移
php artisan module:migrate Attribute
-
通过 AsgardCMS 的模块命令执行发布
php artisan module:publish Attribute
-
完成!
用法
将 EAV 添加到 Eloquent 模型
要将 EAV 功能添加到您的 Eloquent 模型,只需使用 \Module\Attribute\Traits\Attributable
特性和实现 \Module\Attribute\Contracts\AttributesInterface
,如下所示:
use \Module\Attribute\Contracts\AttributesInterface use \Module\Attribute\Traits\Attributable class Book extends Model implements AttributesInterface { use Attributable; }
在 Eloquent 模型上配置属性
在您的实体上添加 $systemAttributes
以在代码级别添加属性
use \Module\Attribute\Contracts\AttributesInterface use \Module\Attribute\Traits\Attributable class Book extends Model implements AttributesInterface { use Attributable; ... // Set systemAttributes to define EAV attributes protected $systemAttributes = [ 'isbn' => [ 'type' => 'input' ], 'media' => [ 'type' => 'checkbox', 'options' => [ 'audio-cd', 'audio-book', 'e-book', ] ] ]; }
可用的 SystemAttributes 参数
type : 输入类型的字符串(以下列出)
input
: input[type=text]textarea
: textarearadio
: input[type=radio]checkbox
: input[type=checkbox]select
: selectmultiselect
: select[multiple]
options : 选项键的数组
has_translatable_values : 布尔值
关于 Laraplug
LaraPlug 是一个基于 AsgardCMS 构建的 opensource 电子商务项目。
贡献
我们欢迎任何 pull-requests 或 issues :)