From 8b95c89cfe86189fa46161cd1a16792851dd6fa9 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Fri, 28 Jun 2019 16:03:52 +0200 Subject: [PATCH] #2843 --- .../Magic/Models/CubistMagicAbstractModel.php | 33 ++++--------------- 1 file changed, 6 insertions(+), 27 deletions(-) diff --git a/src/app/Magic/Models/CubistMagicAbstractModel.php b/src/app/Magic/Models/CubistMagicAbstractModel.php index 6b75a2f..a80efbe 100644 --- a/src/app/Magic/Models/CubistMagicAbstractModel.php +++ b/src/app/Magic/Models/CubistMagicAbstractModel.php @@ -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 */ -- 2.39.5