where('user_id', auth()->id()) ->whereKey($value) ->first(); if ($parent === null) { $fail(__('The selected parent category is invalid.')); return; } if ($this->category !== null && $this->tree->wouldCreateCycle($this->category, $parent->id)) { $fail(__('A category cannot be nested under itself or one of its children.')); return; } $subtreeDepth = $this->category !== null ? $this->tree->subtreeDepth($this->category) : 1; if ($this->tree->depth($parent) + $subtreeDepth > Category::MAX_DEPTH) { $fail(__('Categories can only be nested up to :max levels deep.', ['max' => Category::MAX_DEPTH])); } } }