问题
I want to write a function where a multidimensional array with the following structure:
{
"id_coretable": 1,
"Internal_key": "UPDATED1",
"extensiontable_itc": {
"description_itc": "UPDATED1"
},
"extensiontable_sysops": {
"description_sysops": "UPDATED1"
}
}
updates a multidimensional model/collection (i can create either of them, whatever the actual solution to this problem might require) with basically the same structure:
{
"id_coretable": 1,
"Internal_key": "NOTYETUPDATED1",
"extensiontable_itc": {
"description_itc": "NOTYETUPDATED1"
},
"extensiontable_sysops": {
"description_sysops": "NOTYETUPDATED1"
}
}
This model was fetched like this:
$model = coretable::with($OneDimArrayOfTablenames);
I've already searched stackoverflow for questions regarding the updating of a model with input in the form of an array. I found a rather effective solution here:
Laravel 5 Array with key save in model
See the accepted answer there.
However:
$model->fill($twoDimArrayWithUpdates);
$model->save();
Does not do the job.
It only updates the elements from the outer array, namely Internal_key
.
It does not "descend" deeper into the target array, and maybe it also doesn't even descend deeper into the source array. I don't really know how to observe this closer though^^
Can I do something about this? In the declaration of the models of the affected tables, I made the attributes to which these updates shall be mass assigned:
protected $fillable = [
'name_of_the_attribute'
];
So I guess this should not be the problem. If you require more info about my DB structure or the model, just tell me. I just tried to keep this question as focussed as possible and so far I dont think you need anything else.
来源:https://stackoverflow.com/questions/60092037/laravel-lumen-eloquent-update-coretablewithonedimarrayoftablenames-with-m