protected $_databaseType = 'text';
protected $_translatable = true;
+
+ public function filterValue($value)
+ {
+ if (null === $value) {
+ return '[]';
+ }
+
+ if (is_string($value)) {
+ $string = true;
+ $decoded = json_decode($value, 1);
+ } else {
+ $decoded = $value;
+ }
+ $res = [];
+ if (!is_array($decoded)) {
+ dd($decoded);
+ }
+ foreach ($decoded as $i => $item) {
+ if (!isset($item['id']) || $item['id'] == '') {
+ $item['id'] = $i;
+ }
+ $res[$i] = $item;
+ }
+ if ($string) {
+ $value = json_encode($res);
+ } else {
+ $value = $res;
+ }
+
+ return parent::filterValue($value);
+ }
}
return $this->getMedia($c);
}
+ public function getAttribute($key)
+ {
+ $value = parent::getAttribute($key);
+ $f = $this->getField($key);
+ if (null === $f) {
+ return $value;
+ }
+ return $f->filterValue($value);
+ }
}