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()`.
Tags
Table of Contents
- $modelsToSave : array<string|int, mixed>
- deferPurgedSaveAttributes() : void
- Removes an array of attributes from the model. If the model implements the Purgeable trait, this is preferred over the internal logic.
- prepareModelsToSave() : array<string|int, mixed>
- Takes a model and fills it with data from a multidimensional array.
- setModelAttributes() : void
- Sets a data collection to a model attributes, relations are also set.
Properties
$modelsToSave
protected
array<string|int, mixed>
$modelsToSave
= []
List of prepared models that require saving.
Methods
deferPurgedSaveAttributes()
Removes an array of attributes from the model. If the model implements the Purgeable trait, this is preferred over the internal logic.
protected
deferPurgedSaveAttributes(Model $model, array<string|int, mixed> $attributesToPurge) : void
Parameters
- $model : Model
-
Model to adjust.
- $attributesToPurge : array<string|int, mixed>
-
Attribute values to remove from the model.
Return values
void —prepareModelsToSave()
Takes a model and fills it with data from a multidimensional array.
protected
prepareModelsToSave(Model $model, array<string|int, mixed> $saveData) : array<string|int, mixed>
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
- $model : Model
-
Model to fill.
- $saveData : array<string|int, mixed>
-
Attribute values to fill model.
Return values
array<string|int, mixed> —The collection of models to save.
setModelAttributes()
Sets a data collection to a model attributes, relations are also set.
protected
setModelAttributes(Model $model, array<string|int, mixed> $saveData) : void
Parameters
- $model : Model
-
Model to fill.
- $saveData : array<string|int, mixed>
-
Attribute values to fill model.