If I have a table like this:
+--------+-------------------+-----------+
| 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 |
+--------+-------------------+-----------+
Using Laravel Eloquent:
$sortOrder = [1, 2, 0, 3, 4];
$list = Type::where('Type', '=', 'B')
->orderBy('nOrder', 'ASC')
->update(['nOrder' => ??? ]); // how can i apply the $sortOrder values at ???
My guess would be, the update would look something like this:
->update(['nOrder' => $sortOrder[DB::raw('`nOrder`')] ]); // this doesn't work though
The expected results would look like this:
+--------+-------------------+-----------+
| 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 |
+--------+-------------------+-----------+
orderis a reserved word - a poor choice for a table/column identifier.$sortOrderthere is no one step I guess.