Level 63
Solved => it was a fillable problem.
Hello,
I have a code which seems correct to reorder some steps, but the result is not good.
I receive the right old and new index. The order in the database starts at 0, exactly like the index.
public function sortSteps(Request $request, Quest $quest)
{
$oldOrder = $request->oldIndex;
$newOrder = $request->newIndex;
$step = Step::where('quest_id', $quest->id)->where('order', $oldOrder)->first();
if ($newOrder > $oldOrder) {
Step::where('quest_id', $quest->id)->where('order', '<=', $newOrder)->where('order', '>', $oldOrder)->decrement('order');
} else {
Step::where('quest_id', $quest->id)->where('order', '>=', $newOrder)->where('order', '<', $oldOrder)->increment('order');
}
$step->update(['order' => $newOrder]);
}
Do you see any error ?
Thanks for your help.
V
Solved => it was a fillable problem.
Please or to participate in this conversation.