Example #1
0
 /**
  * Sets a data collection to a model attributes, relations will also be set.
  * @param array $saveData Data to save.
  * @param Model $model Model to save to
  * @return array The collection of models to save.
  */
 protected function setModelAttributes($model, $saveData)
 {
     $this->modelsToSave[] = $model;
     if (!is_array($saveData)) {
         return;
     }
     $singularTypes = ['belongsTo', 'hasOne', 'morphOne'];
     foreach ($saveData as $attribute => $value) {
         $isNested = $attribute == 'pivot' || $model->hasRelation($attribute) && in_array($model->getRelationType($attribute), $singularTypes);
         if ($isNested && is_array($value)) {
             $this->setModelAttributes($model->{$attribute}, $value);
         } elseif ($value !== FormField::NO_SAVE_DATA) {
             $model->{$attribute} = $value;
         }
     }
 }
Example #2
0
 /**
  * Sets a data collection to a model attributes, relations will also be set.
  * @param array $saveData Data to save.
  * @param Model $model Model to save to
  * @return array The collection of models to save.
  */
 protected function setModelAttributes($model, $saveData)
 {
     $this->modelsToSave[] = $model;
     if (!is_array($saveData)) {
         return;
     }
     $singularTypes = ['belongsTo', 'hasOne', 'morphOne'];
     foreach ($saveData as $attribute => $value) {
         if (is_array($value) && $model->hasRelation($attribute) && in_array($model->getRelationType($attribute), $singularTypes)) {
             $this->setModelAttributes($model->{$attribute}, $value);
         } else {
             $model->{$attribute} = $value;
         }
     }
 }