Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

orj's avatar
Level 3

Node must exists error in Nestedset

Im using kalnoy/nestedset package for nesting categories but there's an error when creating a new child category

Here is thei first part of the error after submitting the create form

(1/1) LogicException
Node must exists.
in NodeTrait.php (line 1181)

Here is the code that i use for my Post categories model

use Illuminate\Database\Eloquent\Model;

use Kalnoy\Nestedset\NodeTrait;


class PostCategories extends Model
{
    use NodeTrait;

    protected $fillable = [
        'title', 'parent_id',
    ];
}

Here is the code to store in my Post categories controller

$category = PostCategories::create($input->all());

        return redirect()
            ->route('post_categories.show', [ $category->getKey() ]);

I dont know if i just missed something in the package documentation while implementing it

Regards

0 likes
5 replies
Rustery's avatar

Hi @Aqeel94321 . You should fix the tree to fill _lft and _rgt columns. Just execute this code in php artisan tinker console:

MyModel::fixTree();
3 likes

Please or to participate in this conversation.