Laraplug Attribute is a EAV e-commerce module, built on top of AsgardCMS platform.
Successfully implemented on laraplug/product-module
-
Install the package via composer:
composer require laraplug/attribute-module
-
Execute migrations via AsgardCMS's module command:
php artisan module:migrate Attribute
-
Execute publish via AsgardCMS's module command:
php artisan module:publish Attribute
-
Done!
To add EAV functionality to your Eloquent model, just use the \Module\Attribute\Traits\Attributable
trait and implement \Module\Attribute\Contracts\AttributesInterface
like this:
use \Module\Attribute\Contracts\AttributesInterface
use \Module\Attribute\Traits\Attributable
class Book extends Model implements AttributesInterface
{
use Attributable;
}
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',
]
]
];
}
type : String of input type (list below)
input
: input[type=text]textarea
: teaxarearadio
: input[type=radio]checkbox
: input[type=checkbox]select
: selectmultiselect
: select[multiple]
options : Array of option keys
has_translatable_values : boolean
LaraPlug is a opensource e-commerce project built on top of AsgardCMS.
We welcome any pull-requests or issues :)