$cases = [];
$ids = [];
$params = [];
foreach ($request->data as $value => $id) {
$id = (int) $id;
$cases[] = "WHEN {$id} then ?";
$params[] = $value;
$ids[] = $id;
}
$ids = implode(',', $ids);
$cases = implode(' ', $cases);
\DB::update("UPDATE `table_name` SET `position` = CASE `id` {$cases} END WHERE `id` in ({$ids})", $params);