public function getAttribute($key)
{
if (isset($this->attributes[$key])) {
return $this->attributes[$key];
}
//
if ($key == 'website_id') {
$websites = $this->websites()->get()->pluck('id');
return $websites->all();
}
if ($key == 'price') {
return $this->getPrice();
}
//
if ($key == 'category_id') {
$categories = $this->categories()->get()->pluck('id');
return $categories->all();
}
if ($key == 'reviews') {
return $this->reviews()->get();
}
$value = null;
//$cacheKey = ProductAttribute::class . "_" . $key;
//if(Cache::has($cacheKey)) {
// $productAttribute = Cache::get($cacheKey);
//} else {
$productAttribute = ProductAttribute::where('identifier', '=', $key)->get()->first();
//Cache::put($cacheKey , $productAttribute, $minute = 100);
//}
if (null == $productAttribute) {
return;
}
switch ($productAttribute->type) {
case 'VARCHAR':
$value = $this->_getProductVarcharValue($productAttribute);
break;
case 'INTEGER':
$value = $this->_getProductIntegerValue($productAttribute);
break;
case 'FLOAT':
$value = $this->_getProductFloatValue($productAttribute);
break;
case 'TEXT':
$value = $this->_getProductTextValue($productAttribute);
break;
case 'DATETIME':
$value = $this->_getProductdatetimeValue($productAttribute);
break;
default:
break;
}
return $value;
}