etrepat / baum

Baum is an implementation of the Nested Set pattern for Laravel's Eloquent ORM.
http://etrepat.com/baum
MIT License
2.24k stars 459 forks source link

Create a node Object to add child for it #250

Closed sobhanatar closed 7 years ago

sobhanatar commented 7 years ago

Hi

How can I construct a node so I can make child for it using $child2 = Category::create(['name' => 'Child 2']); $child2->makeChildOf($root);

I have sent parent_id from my view to my controller and my problem is that I can't find a way to create my $secondOrThirdLevelRootToBeFatherOfMyNewChild

In other words I want to know how can I get a node object from its id?

Thanks

sobhanatar commented 7 years ago

As it seems you'd stopped answering to your question and for those that might gut stock in my situation can do the following to get a node object:

$ancestor = YourModelName::where('id', '=', $request->get('parent_id'))->first();

and after that create a child for this object using the way showed in documentation:

$ancestor->children()->create([...]);