FormModelSaver

Implements special logic for processing form data, typically from from postback, and filling the model attributes and attributes of any related models. This is a customized, safer and simplified version of $model->push().

 trait Backend\Traits\FormModelSaver

Properties

protected $modelsToSave : array

List of prepared models that require saving.

Methods

protected deferPurgedSaveAttributes (Winter\Storm\Database\Model $model, array $attributesToPurge) : void

Removes an array of attributes from the model. If the model implements the Purgeable trait, this is preferred over the internal logic.

Parameters
Property Description
$model

Model to adjust.

$attributesToPurge
array

Attribute values to remove from the model.

Returns
void

protected prepareModelsToSave (Winter\Storm\Database\Model $model, array $saveData) : array

Takes a model and fills it with data from a multidimensional array.

If an attribute is found to be a relationship, that relationship is also filled.

$modelsToSave = $this->prepareModelsToSave($model, [...]);

foreach ($modelsToSave as $modelToSave) {
    $modelToSave->save();
}
Parameters
Property Description
$model

Model to fill.

$saveData
array

Attribute values to fill model.

Returns
array

The collection of models to save.

protected setModelAttributes (Winter\Storm\Database\Model $model, array $saveData) : void

Sets a data collection to a model attributes, relations are also set.

Parameters
Property Description
$model

Model to fill.

$saveData
array

Attribute values to fill model.

Returns
void
Copyright © 2024 Winter CMS