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

87 lines
2.1 KiB
PHP
Raw Normal View History

2018-07-31 07:50:54 +00:00
<?php
namespace Webkul\Product\Models;
use Illuminate\Database\Eloquent\Model;
2019-02-18 07:30:40 +00:00
use Webkul\Attribute\Models\AttributeProxy;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Webkul\Product\Database\Factories\ProductAttributeValueFactory;
2019-02-18 07:30:40 +00:00
use Webkul\Product\Contracts\ProductAttributeValue as ProductAttributeValueContract;
2018-07-31 07:50:54 +00:00
2019-02-18 07:30:40 +00:00
class ProductAttributeValue extends Model implements ProductAttributeValueContract
2018-07-31 07:50:54 +00:00
{
use HasFactory;
2021-06-30 06:20:55 +00:00
/**
* Indicates if the model should be timestamped.
*
* @var bool
*/
public $timestamps = false;
2018-08-09 04:35:13 +00:00
/**
2021-06-30 06:20:55 +00:00
* Attribute type fields.
*
2018-08-09 04:35:13 +00:00
* @var array
*/
public static $attributeTypeFields = [
2020-02-20 06:12:17 +00:00
'text' => 'text_value',
'textarea' => 'text_value',
'price' => 'float_value',
'boolean' => 'boolean_value',
'select' => 'integer_value',
2018-08-09 04:35:13 +00:00
'multiselect' => 'text_value',
2020-02-20 06:12:17 +00:00
'datetime' => 'datetime_value',
'date' => 'date_value',
'file' => 'text_value',
'image' => 'text_value',
'checkbox' => 'text_value',
2018-08-09 04:35:13 +00:00
];
2021-06-30 06:20:55 +00:00
/**
* 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',
2020-03-04 06:32:53 +00:00
'json_value',
];
2018-07-31 07:50:54 +00:00
/**
* Get the attribute that owns the attribute value.
2018-07-31 07:50:54 +00:00
*/
public function attribute(): BelongsTo
2018-07-31 07:50:54 +00:00
{
2019-02-18 07:30:40 +00:00
return $this->belongsTo(AttributeProxy::modelClass());
2018-07-31 07:50:54 +00:00
}
/**
* Get the product that owns the attribute value.
*/
public function product(): BelongsTo
2018-07-31 07:50:54 +00:00
{
2019-02-18 07:30:40 +00:00
return $this->belongsTo(ProductProxy::modelClass());
2018-07-31 07:50:54 +00:00
}
/**
* Create a new factory instance for the model.
*
* @return ProductAttributeValueFactory
*/
protected static function newFactory(): ProductAttributeValueFactory
{
return ProductAttributeValueFactory::new();
}
2021-06-30 06:20:55 +00:00
}