What would be the best way to update data from associative array? I recieve this array in my controller:

"sort" =&gt; array:6 [
    0 =&gt; array:2 [
        "id" =&gt; "153"
        "sort" =&gt; "2"
    ]
    1 =&gt; array:2 [
        "id" =&gt; "152"
        "sort" =&gt; "1"
    ]
    2 =&gt; array:2 [
        "id" =&gt; "154"
        "sort" =&gt; "3"
    ]
    3 =&gt; array:2 [
        "id" =&gt; "166"
        "sort" =&gt; "4"
    ]
    4 =&gt; array:2 [
        "id" =&gt; "155"
        "sort" =&gt; "5"
    ]
    5 =&gt; array:2 [
        "id" =&gt; "156"
        "sort" =&gt; "6"
    ]
]


I have made this and it works:

foreach ($request['sort'] as $model) {
    Model::where('id', $model['id'])-&gt;update(['sort' =&gt; $model['sort']]);
}


There is probably a better way to do this....
This will make so many requests on DB how many items there are inside that array....
Anyone has better ideas? Maybe there is a way to make that update all at once so there is only one request on DB?
"Premature optimization is the root of all evil."


As long as this code works and causes no problem, nothing should be really done. Trying to "improve" it, most likely you will cause a severe harm to readability, maintainability and - ironically - performance. 

The only thing could be suggested out of the blue is to wrap the loop in a transaction. It will be a sensible move by itself, and and also could improve the speed in case of some certain settings of the database engine.