laraplug/attribute-module

安装: 201

依赖项: 2

建议者: 0

安全: 0

星标: 1

关注者: 3

分支: 0

开放问题: 0

类型:asgard-module

v0.3.1 2018-03-09 15:02 UTC

This package is not auto-updated.

Last update: 2024-09-29 05:27:42 UTC


README

Latest Stable Version Software License Daily Downloads Monthly Downloads Total Downloads PHP7 Compatible

Laraplug 属性

Laraplug 属性 是一个基于 AsgardCMS 平台的 EAV 电子商务模块。

已在 laraplug/product-module 中成功实现

目录

安装

  1. 通过 composer 安装包

    composer require laraplug/attribute-module
  2. 通过 AsgardCMS 的模块命令执行迁移

    php artisan module:migrate Attribute
  3. 通过 AsgardCMS 的模块命令执行发布

    php artisan module:publish Attribute
  4. 完成!

用法

将 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 : textarea
  • radio : input[type=radio]
  • checkbox : input[type=checkbox]
  • select : select
  • multiselect : select[multiple]

options : 选项键的数组

has_translatable_values : 布尔值

关于 Laraplug

LaraPlug 是一个基于 AsgardCMS 构建的 opensource 电子商务项目。

贡献

我们欢迎任何 pull-requests 或 issues :)