belongsTo(Product::class); } public function getMetaAttribute(){ $data = json_decode($this->data,true); if ($data == null) { return []; } $props = $this->product->category->props()->whereIn('name', array_keys($data))->get(); $result = []; foreach ($props as $key => $prop) { $result[$prop->name] = [ 'label' => $prop->label, 'human_value' => '', 'type' => $prop->type, 'value' => $data[$prop->name], ]; switch ($prop->type) { case 'color': $result[$prop->name]['human_value'] = "
 
"; break; case 'checkbox': $result[$prop->name]['human_value'] = $data[$prop->name] ? '' : ''; break; case 'select': case 'singlemulti': $tmp = $prop->datas; if (!is_array($data[$prop->name])) { if (isset($tmp[$data[$prop->name]])){ $result[$prop->name]['human_value'] = $tmp[$data[$prop->name]]; }else{ $result[$prop->name]['human_value'] = '-'; } } else { $result[$prop->name]['human_value'] = ''; $tmp = $prop->datas; foreach ($data[$prop->name] as $k => $v) { $result[$prop->name]['human_value'] = $tmp[$v] . ', '; } $result[$prop->name]['human_value'] = trim($result[$prop->name], ' ,'); } break; default: if (is_array($data[$prop->name])) { $result[$prop->name]['human_value'] = ''.implode(' ', $data[$prop->name]).''; } else { if ($data[$prop->name] == '' || $data[$prop->name] == null) { $result[$prop->name]['human_value'] = '-'; }else{ $result[$prop->name]['human_value'] = $data[$prop->name]; } } } $result[$prop->name]['human_value'] .= ' ' . $prop->unit; } return $result; } }