title: How to apply values from array and update rows using Laravel Eloquent?
body: <p>If I have a table like this:</p>
  
  <pre><code>+--------+-------------------+-----------+
  | ID     | Type              |  nOrder   |
  +--------+-------------------+-----------+
  | 1      | A                 | 0         |
  | 2      | A                 | 1         |
  | 3      | A                 | 2         |
  | 4      | B                 | 0         |
  | 5      | B                 | 1         |
  | 6      | B                 | 2         |
  | 7      | B                 | 3         |
  | 8      | B                 | 4         |
  | 9      | C                 | 0         |
  | 10     | C                 | 1         |
  +--------+-------------------+-----------+
  </code></pre>
  
  <p>Using Laravel Eloquent:</p>
  
  <pre><code>$sortOrder = [1, 2, 0, 3, 4];
  
  $list = Type::where('Type', '=', 'B')
      -&gt;orderBy('nOrder', 'ASC')
      -&gt;update(['nOrder' =&gt; ??? ]); // how can i apply the $sortOrder values at ???
  </code></pre>
  
  <p>My guess would be, the update would look something like this:</p>
  
  <pre><code>-&gt;update(['nOrder' =&gt; $sortOrder[DB::raw('`nOrder`')] ]); // this doesn't work though
  </code></pre>
  
  <p>The expected results would look like this:</p>
  
  <pre><code>+--------+-------------------+-----------+
  | ID     | Type              |  nOrder   |
  +--------+-------------------+-----------+
  | 1      | A                 | 0         |
  | 2      | A                 | 1         |
  | 3      | A                 | 2         |
  | 4      | B                 | 1         |
  | 5      | B                 | 2         |
  | 6      | B                 | 0         |
  | 7      | B                 | 3         |
  | 8      | B                 | 4         |
  | 9      | C                 | 0         |
  | 10     | C                 | 1         |
  +--------+-------------------+-----------+
  </code></pre>