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()
.
$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.
Property | Type | Description |
---|---|---|
$model | Winter\Storm\Database\Model |
Model to adjust. |
$attributesToPurge | array |
array
Attribute values to remove from the model. |
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();
}
Property | Type | Description |
---|---|---|
$model | Winter\Storm\Database\Model |
Model to fill. |
$saveData | array |
array
Attribute values to fill model. |
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.
Property | Type | Description |
---|---|---|
$model | Winter\Storm\Database\Model |
Model to fill. |
$saveData | array |
array
Attribute values to fill model. |