adrianskierniewski / eloquent-tree Goto Github PK
View Code? Open in Web Editor NEWEloquent Tree is a tree model for Laravel Eloquent ORM.
License: MIT License
Eloquent Tree is a tree model for Laravel Eloquent ORM.
License: MIT License
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;
}
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
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.
Does anyone have a snippet to share showing how to listen and respond to a TreeEvents
like updatedParent
?
Thank you. :)
Do you have plans to support Laravel 5?
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);
});
}
Whenever I try to pass presenter class to buildTree method, I get few errors (issues):
// remove "Tree" declaration here
protected function _addChildToCollection(Tree &$child) {
// to something
protected function _addChildToCollection(&$child) {
if ( isset($root) )
{
return isset($presenter) && class_exists($presenter) ? new $presenter($root) : $root;
}
else
{
return FALSE;
}
How can I modify the migration and choose another table name?
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();
}
Is there any plan to upgrade to Laravel 5 ?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.