Open johnRivs opened 7 years ago
What I have:
$child_1 = factory(User::class)->states('active')->create(); $child_1_1 = factory(User::class)->states('active')->create()->makeChildOf($child_1); $child_1_1_1 = factory(User::class)->states('active')->create()->makeChildOf($child_1_1); $child_1_1_2 = factory(User::class)->states('active')->create()->makeChildOf($child_1_1); $child_1_1_3 = factory(User::class)->states('active')->create()->makeChildOf($child_1_1); $child_1_1_4 = factory(User::class)->create()->makeChildOf($child_1_1); $child_1_1->cap();
When I do:
public function cap() { $actives = $this->children() ->whereActive(true) ->limit(2) ->get(); $actives->each(function($active) { $active->makeChildOf($this->parent); }); }
Only the first $active ends up being a child of $this->parent (which is $child_1).
$active
$this->parent
$child_1
When I dump $child_1->children after that, I only see $child_1_1 and $child_1_1_1, instead of $child_1_1, $child_1_1_1 and $child_1_1_2.
$child_1->children
$child_1_1
$child_1_1_1
$child_1_1_2
PS: It'd be even better if we could could have something like $actives->makeChildrenOf($user).
$actives->makeChildrenOf($user)
What I have:
When I do:
Only the first
$active
ends up being a child of$this->parent
(which is$child_1
).When I dump
$child_1->children
after that, I only see$child_1_1
and$child_1_1_1
, instead of$child_1_1
,$child_1_1_1
and$child_1_1_2
.PS: It'd be even better if we could could have something like
$actives->makeChildrenOf($user)
.