25 lines
669 B
PHP
25 lines
669 B
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Modules\CustomField\Actions;
|
||
|
|
|
||
|
|
use App\Modules\CustomField\Models\CustomFieldDefinition;
|
||
|
|
use Illuminate\Support\Facades\DB;
|
||
|
|
|
||
|
|
final class ReorderCustomFieldDefinitionsAction
|
||
|
|
{
|
||
|
|
/**
|
||
|
|
* Reassign sort_order to match the given ordered list of ids,
|
||
|
|
* normalizing positions to a contiguous 0..n-1 sequence.
|
||
|
|
*
|
||
|
|
* @param array<int, int> $ids
|
||
|
|
*/
|
||
|
|
public function handle(array $ids): void
|
||
|
|
{
|
||
|
|
DB::transaction(function () use ($ids) {
|
||
|
|
foreach (array_values($ids) as $index => $id) {
|
||
|
|
CustomFieldDefinition::where('id', $id)->update(['sort_order' => $index]);
|
||
|
|
}
|
||
|
|
});
|
||
|
|
}
|
||
|
|
}
|