laraplug/attribute-module

Installs: 201

Dependents: 2

Suggesters: 0

Security: 0

Stars: 1

Watchers: 3

Forks: 0

Open Issues: 0

Type:asgard-module

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

This package is not auto-updated.

Last update: 2024-11-10 06:12:25 UTC


README

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

Laraplug Attribute

Laraplug Attribute is a EAV e-commerce module, built on top of AsgardCMS platform.

Successfully implemented on laraplug/product-module

Table Of Contents

Installation

  1. Install the package via composer:

    composer require laraplug/attribute-module
  2. Execute migrations via AsgardCMS's module command:

    php artisan module:migrate Attribute
  3. Execute publish via AsgardCMS's module command:

    php artisan module:publish Attribute
  4. Done!

Usage

Add EAV to Eloquent model

To add EAV functionality to your Eloquent model, just use the \Module\Attribute\Traits\Attributable trait and implement \Module\Attribute\Contracts\AttributesInterfacelike this:

use \Module\Attribute\Contracts\AttributesInterface
use \Module\Attribute\Traits\Attributable

class Book extends Model implements AttributesInterface
{
    use Attributable;
}

Configure attributes on Eloquent model

Add $systemAttributes on your entity to add attributes on code-level:

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',
            ]
        ]
    ];
}

Available SystemAttributes Parameters

type : String of input type (list below)

  • input : input[type=text]
  • textarea : teaxarea
  • radio : input[type=radio]
  • checkbox : input[type=checkbox]
  • select : select
  • multiselect : select[multiple]

options : Array of option keys

has_translatable_values : boolean

About Laraplug

LaraPlug is a opensource e-commerce project built on top of AsgardCMS.

Contributing

We welcome any pull-requests or issues :)