Skip to content

Commit 74ec0eb

Browse files
authored
Prevent invalid oldparent error when parent is changed from root
1 parent 650da77 commit 74ec0eb

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/Controllers/ModelController.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -219,14 +219,12 @@ public function changeParent($slug, Request $request, $id)
219219
$this->checkSlug($slug, 'update');
220220
$row = $this->model()::findOrFail($id);
221221

222-
// Get the parent and oldparent from Input, make null if needed
223-
$parent = $request->input('parent');
224-
$oldparent = $request->input('oldparent');
225-
if ($oldparent < 1) $oldparent = null;
226-
if ($parent < 1) $parent = null;
222+
// Get the parent and oldparent from Input as integer
223+
$parent = (int)$request->input('parent');
224+
$oldparent = (int)$request->input('oldparent');
227225

228226
// Check if oldparent matches the actual id for safety
229-
if ($row->parent != $oldparent) die('Invalid oldparent ' . $oldparent);
227+
if ($row->parent != $oldparent) return ('Invalid oldparent "' . $row->parent . '" != "' . $oldparent . '"');
230228

231229
// Save the new parent
232230
$row->parent = $parent;

0 commit comments

Comments
 (0)