]> _ Git - cubist_cms-back.git/commitdiff
#2843
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 28 Jun 2019 14:03:52 +0000 (16:03 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 28 Jun 2019 14:03:52 +0000 (16:03 +0200)
src/app/Magic/Models/CubistMagicAbstractModel.php

index 6b75a2ffaf5d9ae66036405207dc40ab488a43b9..a80efbefa66e32b9bbb7a9396fded625c3e835c3 100644 (file)
@@ -106,33 +106,6 @@ class CubistMagicAbstractModel extends Model implements HasMedia
 
     }
 
-    /**
-     * Create translated items as json.
-     *
-     * @param array $attributes
-     * @return static
-     */
-    public static function create(array $attributes = [])
-    {
-        $locale = $attributes['locale'] ?? \App::getLocale();
-        $attributes = array_except($attributes, ['locale']);
-        $non_translatable = [];
-
-        $model = new static();
-
-        // do the actual saving
-        foreach ($attributes as $attribute => $value) {
-            if ($model->isTranslatableAttribute($attribute)) { // the attribute is translatable
-                $model->setTranslation($attribute, $locale, $value);
-            } else { // the attribute is NOT translatable
-                $non_translatable[$attribute] = $value;
-            }
-        }
-        $model->fill($non_translatable)->save();
-
-        return $model;
-    }
-
     public function getPrimaryKey()
     {
         return $this->primaryKey;
@@ -485,6 +458,12 @@ class CubistMagicAbstractModel extends Model implements HasMedia
         return $this->updateTranslations($attributes, $options);
     }
 
+    public function create(array $attributes = [])
+    {
+        $attributes = Json::decodeRecursive($attributes, Json::TYPE_ARRAY);
+        return $this->createTranslations($attributes);
+    }
+
     /**
      * @param $controller CubistMagicController
      */