Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/NodeTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -749,8 +749,9 @@ public function newCollection(array $models = array())
* Use `children` key on `$attributes` to create child nodes.
*
* @param self $parent
* @param callable $callback
*/
public static function create(array $attributes = [], self $parent = null)
public static function create(array $attributes = [], self $parent = null, callable $callbackForEachChild = null)
{
$children = array_pull($attributes, 'children');

Expand All @@ -766,9 +767,12 @@ public static function create(array $attributes = [], self $parent = null)
$relation = new EloquentCollection;

foreach ((array)$children as $child) {
$relation->add($child = static::create($child, $instance));
$relation->add($child = static::create($child, $instance, $callbackForEachChild));

$child->setRelation('parent', $instance);

if(isset($callback))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add braces as this is not PSR-2 compliant code.

call_user_func($callbackForEachChild, $child);
}

$instance->refreshNode();
Expand Down