¨4.0.1¨
This commit is contained in:
@@ -12,20 +12,24 @@ class Attribute extends Model
|
||||
{
|
||||
use Translatable, Sluggable;
|
||||
|
||||
/**
|
||||
* The attributes that are translatable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $translatedAttributes = ['name'];
|
||||
/**
|
||||
* The relations to eager load on every query.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $with = ['translations'];
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = ['attribute_set_id', 'slug', 'is_filterable'];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast to native types.
|
||||
*
|
||||
@@ -34,14 +38,6 @@ class Attribute extends Model
|
||||
protected $casts = [
|
||||
'is_filterable' => 'boolean',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that are translatable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $translatedAttributes = ['name'];
|
||||
|
||||
/**
|
||||
* The attribute that will be slugged.
|
||||
*
|
||||
@@ -49,6 +45,7 @@ class Attribute extends Model
|
||||
*/
|
||||
protected $slugAttribute = 'name';
|
||||
|
||||
|
||||
/**
|
||||
* Perform any actions required after the model boots.
|
||||
*
|
||||
@@ -61,25 +58,6 @@ class Attribute extends Model
|
||||
});
|
||||
}
|
||||
|
||||
public function attributeSet()
|
||||
{
|
||||
return $this->belongsTo(AttributeSet::class);
|
||||
}
|
||||
|
||||
public function categories()
|
||||
{
|
||||
return $this->belongsToMany(Category::class, 'attribute_categories');
|
||||
}
|
||||
|
||||
public function values()
|
||||
{
|
||||
return $this->hasMany(AttributeValue::class)->orderBy('position');
|
||||
}
|
||||
|
||||
public function table()
|
||||
{
|
||||
return new AttributeTable($this->with('attributeSet'));
|
||||
}
|
||||
|
||||
public function saveRelations(array $attributes)
|
||||
{
|
||||
@@ -87,6 +65,13 @@ class Attribute extends Model
|
||||
$this->saveValues(array_get($attributes, 'values', []));
|
||||
}
|
||||
|
||||
|
||||
public function categories()
|
||||
{
|
||||
return $this->belongsToMany(Category::class, 'attribute_categories');
|
||||
}
|
||||
|
||||
|
||||
public function saveValues($values = [])
|
||||
{
|
||||
$ids = $this->getDeleteCandidates($values);
|
||||
@@ -103,6 +88,25 @@ class Attribute extends Model
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function values()
|
||||
{
|
||||
return $this->hasMany(AttributeValue::class)->orderBy('position');
|
||||
}
|
||||
|
||||
|
||||
public function attributeSet()
|
||||
{
|
||||
return $this->belongsTo(AttributeSet::class);
|
||||
}
|
||||
|
||||
|
||||
public function table()
|
||||
{
|
||||
return new AttributeTable($this->with('attributeSet'));
|
||||
}
|
||||
|
||||
|
||||
private function getDeleteCandidates($values = [])
|
||||
{
|
||||
return $this->values()
|
||||
|
||||
@@ -10,13 +10,18 @@ class AttributeSet extends Model
|
||||
{
|
||||
use Translatable;
|
||||
|
||||
/**
|
||||
* The attributes that are translatable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $translatedAttributes = ['name'];
|
||||
/**
|
||||
* The relations to eager load on every query.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $with = ['translations'];
|
||||
|
||||
/**
|
||||
* The attributes that aren't mass assignable.
|
||||
*
|
||||
@@ -24,18 +29,13 @@ class AttributeSet extends Model
|
||||
*/
|
||||
protected $guarded = [];
|
||||
|
||||
/**
|
||||
* The attributes that are translatable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $translatedAttributes = ['name'];
|
||||
|
||||
public function attributes()
|
||||
{
|
||||
return $this->hasMany(Attribute::class);
|
||||
}
|
||||
|
||||
|
||||
public function table()
|
||||
{
|
||||
return new AdminTable($this->newQuery());
|
||||
|
||||
@@ -9,24 +9,22 @@ class AttributeValue extends Model
|
||||
{
|
||||
use Translatable;
|
||||
|
||||
/**
|
||||
* The attributes that are translatable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $translatedAttributes = ['value'];
|
||||
/**
|
||||
* The relations to eager load on every query.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $with = ['translations'];
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = ['position'];
|
||||
|
||||
/**
|
||||
* The attributes that are translatable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $translatedAttributes = ['value'];
|
||||
}
|
||||
|
||||
@@ -6,20 +6,24 @@ use Modules\Support\Eloquent\Model;
|
||||
|
||||
class ProductAttribute extends Model
|
||||
{
|
||||
/**
|
||||
* Indicates if the model should be timestamped.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $timestamps = false;
|
||||
/**
|
||||
* The relations to eager load on every query.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $with = ['attribute', 'values'];
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = ['attribute_id'];
|
||||
|
||||
/**
|
||||
* The accessors to append to the model's array form.
|
||||
*
|
||||
@@ -27,28 +31,25 @@ class ProductAttribute extends Model
|
||||
*/
|
||||
protected $appends = ['name'];
|
||||
|
||||
/**
|
||||
* Indicates if the model should be timestamped.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $timestamps = false;
|
||||
|
||||
public function attribute()
|
||||
{
|
||||
return $this->belongsTo(Attribute::class);
|
||||
}
|
||||
|
||||
|
||||
public function values()
|
||||
{
|
||||
return $this->hasMany(ProductAttributeValue::class, 'product_attribute_id');
|
||||
}
|
||||
|
||||
|
||||
public function getNameAttribute()
|
||||
{
|
||||
return $this->attribute->name;
|
||||
}
|
||||
|
||||
|
||||
public function getAttributeSetAttribute()
|
||||
{
|
||||
return $this->attribute->attributeSet->name;
|
||||
|
||||
@@ -27,21 +27,25 @@ class ProductAttributeValue extends Model
|
||||
*/
|
||||
protected $appends = ['value'];
|
||||
|
||||
|
||||
public function exists()
|
||||
{
|
||||
return ! is_null($this->attributeValue);
|
||||
return !is_null($this->attributeValue);
|
||||
}
|
||||
|
||||
|
||||
public function attributeValue()
|
||||
{
|
||||
return $this->belongsTo(AttributeValue::class, 'attribute_value_id');
|
||||
}
|
||||
|
||||
|
||||
public function getIdAttribute()
|
||||
{
|
||||
return $this->attributeValue->id;
|
||||
}
|
||||
|
||||
|
||||
public function getValueAttribute()
|
||||
{
|
||||
return $this->attributeValue->value;
|
||||
|
||||
Reference in New Issue
Block a user