sarga/packages/Webkul/Product/src/Models/ProductAttributeValue.php

87 lines
2.1 KiB
PHP
Executable File

<?php
namespace Webkul\Product\Models;
use Illuminate\Database\Eloquent\Model;
use Webkul\Attribute\Models\AttributeProxy;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Webkul\Product\Database\Factories\ProductAttributeValueFactory;
use Webkul\Product\Contracts\ProductAttributeValue as ProductAttributeValueContract;
class ProductAttributeValue extends Model implements ProductAttributeValueContract
{
use HasFactory;
/**
* Indicates if the model should be timestamped.
*
* @var bool
*/
public $timestamps = false;
/**
* Attribute type fields.
*
* @var array
*/
public static $attributeTypeFields = [
'text' => 'text_value',
'textarea' => 'text_value',
'price' => 'float_value',
'boolean' => 'boolean_value',
'select' => 'integer_value',
'multiselect' => 'text_value',
'datetime' => 'datetime_value',
'date' => 'date_value',
'file' => 'text_value',
'image' => 'text_value',
'checkbox' => 'text_value',
];
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'product_id',
'attribute_id',
'locale',
'channel',
'text_value',
'boolean_value',
'integer_value',
'float_value',
'datetime_value',
'date_value',
'json_value',
];
/**
* Get the attribute that owns the attribute value.
*/
public function attribute(): BelongsTo
{
return $this->belongsTo(AttributeProxy::modelClass());
}
/**
* Get the product that owns the attribute value.
*/
public function product(): BelongsTo
{
return $this->belongsTo(ProductProxy::modelClass());
}
/**
* Create a new factory instance for the model.
*
* @return ProductAttributeValueFactory
*/
protected static function newFactory(): ProductAttributeValueFactory
{
return ProductAttributeValueFactory::new();
}
}