Giter Site home page Giter Site logo

eloquent-tree's Issues

setChildOf on newly created Tree

Hello,

We're using eloquent-tree to handle hierarchy between users. We spoted some performance issue when registering a new user and could track it down to setChildOf().

The problem is that when we want to assign a user newly created to as a child of the currently logged user, path and level are not filled yet. findDescendants() requests all users WHERE path LIKE '<null>%' which returns the whole users table!

I don't know if we're using the package properly, for this purpose, but in any case, I would expect a note in the documentation or something preventing to return the whole table.

What do you think ?

Thanks

Laravel 5

Do you have plans to support Laravel 5?

Can setAsRoot() be called automatically if parent_id is null ?

Hello,

When you modify a record by setting parent_id = null, the path and level values are not updated. Then if you want to call setAsRoot(), it doesn't work because the parent_id value is already null.
Isn't it possible to automatically call setAsRoot() if parent_id is null?

If this is not possible, simply modify the isRoot() function like this to allow setAsRoot() to start even if parent_id is null:

public function isRoot()
{
        // return (empty($this->{$this->getTreeColumn('parent')})) ? true : false;

        return $this->{$this->getTreeColumn('path')} === $this->getKey() . '/'
                && $this->{$this->getTreeColumn('level')} === 0;
}

getRoots() error

Need to add get() onto end of whereNull

/**
     * Gets all root nodes
     *
     * @return \Illuminate\Database\Eloquent\Builder
     */
    public static function getRoots()
    {
        return static::whereNull(static::getTreeColumn('parent'))->get();
    }

Bug Tree::renderRecursiveTree()

In version 2.1 of eloquent-tree in Tree.php, line 511, you have $child->children instead of $child->children(), which in turn is causing Tree:render() to fail to render sub-levels beyodn the first sub-level.

Changing the line to children() appears to fix this issue.

Presenter

Whenever I try to pass presenter class to buildTree method, I get few errors (issues):

  • Presenter has to be a class of "Tree", while I'm building one separated (that's the idea of presenters, heh). I suggest to remove "Tree" requirement from "_addChildToCollection" method:
// remove "Tree" declaration here
protected function _addChildToCollection(Tree &$child) {
// to something
protected function _addChildToCollection(&$child) {
  • Also, root elemend doesn't get presenter applied. Probably buildTree method needs patching, something like (or even better - move representation of element to separate method, so it can be applied to $node and $root):
if ( isset($root) )
{
    return isset($presenter) && class_exists($presenter) ? new $presenter($root) : $root;
}
else
{
    return FALSE;
}

Setting multiple nodes as childs at once?

Is there a way to talk to the database once, instead of using setChildOf() within a loop?

$child_1 = factory(User::class)->states('active')->create();
    $child_1_1 = factory(User::class)->states('active')->create()->setChildOf($child_1);
        $child_1_1_1 = factory(User::class)->states('active')->create()->setChildOf($child_1_1);
        $child_1_1_2 = factory(User::class)->states('active')->create()->setChildOf($child_1_1);
        $child_1_1_3 = factory(User::class)->states('active')->create()->setChildOf($child_1_1);
        $child_1_1_4 = factory(User::class)->create()->setChildOf($child_1_1);

$child_1_1->cap();
public function cap()
{
    $actives = $this->children()
                ->whereActive(true)
                ->limit(2)
                ->get();

    $actives->each(function($active) {
        $active->setChildOf($this->parent);
    });
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.