<?php
 namespace App\Services\Admin\ProductConfigOptionGroup; use App\Models\Admin; use App\Models\ProductConfigOption; use App\Models\ProductConfigOptionGroup; use Illuminate\Support\Facades\DB; class ReorderOptionsService { public function execute( ProductConfigOptionGroup $group, Admin $admin, array $optionIds, ?string $ipAddress = null, ): void { $optionIds = array_values(array_unique($optionIds)); if (empty($optionIds)) { throw new \DomainException('empty_list'); } $valid = ProductConfigOption::where('group_id', $group->id) ->whereIn('id', $optionIds) ->pluck('id')->all(); if (count($valid) !== count($optionIds)) { throw new \DomainException('foreign_option_id'); } DB::transaction(function () use ($optionIds) { foreach ($optionIds as $i => $id) { ProductConfigOption::where('id', $id)->update(['order' => $i + 1]); } }); } } 