From: Vincent Vanwaelscappel Date: Tue, 8 Mar 2022 18:14:49 +0000 (+0100) Subject: wip #5150 @1 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=7b60b5854e36a2d43b6b96e3aaae2918e1a2f0d5;p=cubist_cms-back.git wip #5150 @1 --- diff --git a/src/app/Magic/Fields/Composed.php b/src/app/Magic/Fields/Composed.php new file mode 100644 index 0000000..0a40f7f --- /dev/null +++ b/src/app/Magic/Fields/Composed.php @@ -0,0 +1,13 @@ + $this->_attribute]); + } +} diff --git a/src/app/Magic/Models/CubistMagicAbstractModel.php b/src/app/Magic/Models/CubistMagicAbstractModel.php index d4a8453..8125dd5 100644 --- a/src/app/Magic/Models/CubistMagicAbstractModel.php +++ b/src/app/Magic/Models/CubistMagicAbstractModel.php @@ -937,6 +937,16 @@ class CubistMagicAbstractModel extends Model implements HasMedia return $user->can($permission); } + protected function getAttributesForInsert() + { + $res=parent::getAttributesForInsert(); + foreach ($res as $k=>$v) { + if(is_array($v) || is_object($v)){ + $res[$k]=json_encode($v); + } + } + return $res; + } /** * @param $user CubistMagicAuthenticatable @@ -1113,4 +1123,47 @@ class CubistMagicAbstractModel extends Model implements HasMedia } return null; } + + public function save(array $options = []) + { + $this->mergeAttributesFromCachedCasts(); + + $query = $this->newModelQuery(); + + // If the "saving" event returns false we'll bail out of the save and return + // false, indicating that the save failed. This provides a chance for any + // listeners to cancel save operations if validations fail or whatever. + if ($this->fireModelEvent('saving') === false) { + return false; + } + + // If the model already exists in the database we can just update our record + // that is already in this database using the current IDs in this "where" + // clause to only update this model. Otherwise, we'll just insert them. + if ($this->exists) { + $saved = $this->isDirty() ? + $this->performUpdate($query) : true; + } + + // If the model is brand new, we'll insert it into our database and set the + // ID attribute on the model to the value of the newly inserted row's ID + // which is typically an auto-increment value managed by the database. + else { + $saved = $this->performInsert($query); + + if (! $this->getConnectionName() && + $connection = $query->getConnection()) { + $this->setConnection($connection->getName()); + } + } + + // If the model is successfully saved, we need to do a few more things once + // that is done. We will call the "saved" method here to run any actions + // we need to happen after a model gets successfully saved right here. + if ($saved) { + $this->finishSave($options); + } + + return $saved; + } }