laravel-nestedset icon indicating copy to clipboard operation
laravel-nestedset copied to clipboard

Effective tree structures in Laravel 4-8

Results 149 laravel-nestedset issues
Sort by recently updated
recently updated
newest added

Tree between 2 nodes

[{"_id":"637c68b933d90d275c3d309d","body":"This is described in the readme:\r\nhttps:\/\/github.com\/lazychaser\/laravel-nestedset#getting-a-subtree","issue_id":1660171593605,"origin_id":914187053,"user_origin_id":30020419,"create_time":1631010385,"update_time":1631010385,"id":1669097657598,"updated_at":"2022-11-22T06:14:17.597000Z","created_at":"2022-11-22T06:14:17.597000Z"},{"_id":"637c68b933d90d275c3d309e","body":"hi @David-Petrov yes, you have right, i placed a wrong question. Just corrected.\r\nThanks","issue_id":1660171593605,"origin_id":914196396,"user_origin_id":14801282,"create_time":1631011329,"update_time":1631011329,"id":1669097657600,"updated_at":"2022-11-22T06:14:17.600000Z","created_at":"2022-11-22T06:14:17.600000Z"},{"_id":"637c68b933d90d275c3d309f","body":"@ExaMuff You should keep in mind that this isn't really an issue with the package, but here's a suggestion: you can query your results `withDepth` and then perform a where clause based on the `depth` attribute (which gets subselected in the query). Moreover, if you don't really have a problem with loading a bit more models, you can much more easily do that using laravel collection methods to filter the nodes based on their depth in the ram.","issue_id":1660171593605,"origin_id":914201073,"user_origin_id":30020419,"create_time":1631011824,"update_time":1631011824,"id":1669097657605,"updated_at":"2022-11-22T06:14:17.605000Z","created_at":"2022-11-22T06:14:17.605000Z"},{"_id":"637c68b933d90d275c3d30a0","body":"Hi @David-Petrov, yes I know is not an issue, but yes can be a suggestion for next release.\r\nOk i'll try to find a way, for now i think i'll get `$subtree = ancestorsAndSelf($end_node)`, then cycle `$subtree` until `$node->id != $start_node`","issue_id":1660171593605,"origin_id":914240154,"user_origin_id":14801282,"create_time":1631015779,"update_time":1631015779,"id":1669097657608,"updated_at":"2022-11-22T06:14:17.607000Z","created_at":"2022-11-22T06:14:17.607000Z"}] comment

Hi, is possible in some way get the subtree between 2 nodes? With helper i'm able to check if a node `isDescendantOf` or `isAncestorOf`, but how to get just this...

Hi, On the main page of this repo, the last release seems to be five years old, except that the last tag was pushed in 2021. ![image](https://user-images.githubusercontent.com/3834222/128992951-b38fbb97-b2e7-4225-a5fa-aa2a6ebdcc06.png) ![image](https://user-images.githubusercontent.com/3834222/128993353-95497d74-c24c-4208-938b-6405bede559f.png) I think...

Can't install on Laravel 6

[{"_id":"637c638d0702b96a3080b070","body":"Hi,\r\nFor Laravel 6 I you have to use nestedset v5: `composer require kalnoy\/nestedset: ^5`.\r\n","issue_id":1660171593609,"origin_id":896585131,"user_origin_id":3834222,"create_time":1628668383,"update_time":1628668383,"id":1669096333757,"updated_at":"2022-11-22T05:52:13.757000Z","created_at":"2022-11-22T05:52:13.757000Z"}] comment

Problem 1 - kalnoy/nestedset[v6.0.0, ..., v6.x-dev] require illuminate/support ^7.0|^8.0 -> found illuminate/support[v7.0.0, ..., 7.x-dev, v8.0.0, ..., 8.x-dev] but these were not loaded, likely because it conflicts with another require. -...

Creating child of scoped node

[{"_id":"637c69620702b96a3080b637","body":"Just following on from this, is there a way to save a whole tree of data with the scoped properties automatically set on child nodes?","issue_id":1660171593612,"origin_id":370223720,"user_origin_id":1744544,"create_time":1520165030,"update_time":1520165030,"id":1669097826043,"updated_at":"2022-11-22T06:17:06.043000Z","created_at":"2022-11-22T06:17:06.043000Z"},{"_id":"637c69620702b96a3080b639","body":"Is there any progress on a fix for this issue?","issue_id":1660171593612,"origin_id":895181067,"user_origin_id":12151836,"create_time":1628512011,"update_time":1628512011,"id":1669097826047,"updated_at":"2022-11-22T06:17:06.047000Z","created_at":"2022-11-22T06:17:06.047000Z"},{"_id":"661faa5823eede2dcf063911","body":"+1","issue_id":1660171593612,"origin_id":1509763998,"user_origin_id":13210094,"create_time":1681561780,"update_time":1681561780,"id":1713351256337,"updated_at":"2024-04-17T10:54:16.337000Z","created_at":"2024-04-17T10:54:16.337000Z"}] comment

Is there a way to create child nodes with the scope automatically applied? Below is what I am trying: ``` class Location extends Model { use NodeTrait; protected $guarded =...

enhancement

i am using this package for comments but when i use the model to make a query with a where method on a column it gives no result ! for...

I want to get the id of the child, and if the child has a child, take the id as well and so on, and for the same parent I...

I already have existing system. This package is required left ,right and parent column. But I my structure is upline and downline. How to use this package in my scenario?...

create() with children attribute throwing error

[{"_id":"637c5ebc0702b96a3080ab43","body":"If you're using only Eloquent, you need it to generate events properly and for this, dispatcher should be set up","issue_id":1660171593622,"origin_id":292697440,"user_origin_id":2094856,"create_time":1491630940,"update_time":1491630940,"id":1669095100089,"updated_at":"2022-11-22T05:31:40.088000Z","created_at":"2022-11-22T05:31:40.088000Z"},{"_id":"637c5ebc0702b96a3080ab44","body":"I have the events(which dispatcher is part of) lib like I mentioned in the end on the copy of part of my composer.json.","issue_id":1660171593622,"origin_id":292932935,"user_origin_id":10093456,"create_time":1491826766,"update_time":1491827758,"id":1669095100093,"updated_at":"2022-11-22T05:31:40.092000Z","created_at":"2022-11-22T05:31:40.092000Z"},{"_id":"637c5ebc0702b96a3080ab45","body":"Yes, but you need to set dispatcher on Eloquent","issue_id":1660171593622,"origin_id":292963225,"user_origin_id":2094856,"create_time":1491833904,"update_time":1491833904,"id":1669095100095,"updated_at":"2022-11-22T05:31:40.095000Z","created_at":"2022-11-22T05:31:40.095000Z"},{"_id":"637c5ebc0702b96a3080ab46","body":"Well, I have this slice of code here which I call on my `index.php` file to boot the eloquent:\r\n```\r\n$capsule = new Illuminate\\Database\\Capsule\\Manager();\r\n$capsule->addConnection($container['eloquent']);\r\n$capsule->setAsGlobal();\r\n$capsule->bootEloquent();\r\n```\r\n\r\non `bootEloquent()` there is this:\r\n```\r\n\/\/ If we have an event dispatcher instance, we will go ahead and register it\r\n\/\/ with the Eloquent ORM, allowing for model callbacks while creating and\r\n\/\/ updating \"model\" instances; however, it is not necessary to operate.\r\nif ($dispatcher = $this->getEventDispatcher()) {\r\n Eloquent::setEventDispatcher($dispatcher);\r\n}\r\n```","issue_id":1660171593622,"origin_id":293028672,"user_origin_id":10093456,"create_time":1491847062,"update_time":1492113302,"id":1669095100097,"updated_at":"2022-11-22T05:31:40.097000Z","created_at":"2022-11-22T05:31:40.097000Z"},{"_id":"637c5ebc0702b96a3080ab47","body":"I had a similar problem; I'm seeding a table (Category) with complex nested data using Phinx. In the seeder file (CategoriesSeeder.php - which extends AbstractSeeder) I have an `init` method. In this very method I initialize a new Capsule (`use Illuminate\\Database\\Capsule\\Manager as Capsule;`, add it to a new connection, set as global... as @murilozilli did in [there](https:\/\/github.com\/lazychaser\/laravel-nestedset\/issues\/192#issuecomment-293028672). And then in the `run` method I **set the model's event dispatcher** like so;\r\n```php\r\nCategory::setEventDispatcher($this->capsule->getEventDispatcher());\r\n```\r\nBam, events on the observer (CategoryObserver) working now. Hope this helps.\r\n\r\nEDIT:\r\nRight after the line that sets the model's event dispatcher that line exists (_the data below demonstration only_) and works as expected;\r\n```php\r\nCategory::rebuildTree([\r\n [\r\n 'name' => 'Category 1',\r\n \/\/ other fields of Category instance for \"Category 1\" (if any)\r\n\r\n 'children' => [\r\n 'name' => 'Subcategory 1 of Category 1'\r\n \/\/ other fields of Category instance for \"Subcategory 1 of Category 1\" (if any)\r\n\r\n \/\/ children of \"Subcategory 1 of Category 1\" (if any)\r\n ]\r\n ],\r\n [\r\n 'name' => 'Category 2',\r\n \/\/ other fields of Category instance for \"Category 2\" (if any)\r\n\r\n \/\/ children of \"Category 2\" (if any)\r\n ],\r\n \/\/\r\n]);\r\n```","issue_id":1660171593622,"origin_id":553900894,"user_origin_id":1537985,"create_time":1573740115,"update_time":1593562335,"id":1669095100101,"updated_at":"2022-11-22T05:31:40.100000Z","created_at":"2022-11-22T05:31:40.100000Z"},{"_id":"637c5ebc0702b96a3080ab48","body":"Hi,\r\n\r\ni have the same issue, tried the solution above to get an eventdispatcher instance, but:\r\n$capsule->getEventDispatcher() returns NULL.\r\n\r\nI use eloquent outside laravel and initialize it exactly the way murilozilli does.\r\nJust the nestedset-trait does not work, it prints the same error as stated above =\/","issue_id":1660171593622,"origin_id":651827887,"user_origin_id":5260552,"create_time":1593527202,"update_time":1593527202,"id":1669095100107,"updated_at":"2022-11-22T05:31:40.106000Z","created_at":"2022-11-22T05:31:40.106000Z"},{"_id":"637c5ebc0702b96a3080ab49","body":"I know this is an old question but here is my solution. I'm working with eloquent outside laravel and initialize capsule in this way.\r\n\r\n\r\n```\r\n\/\/ Create new IoC Container instance\r\n$container = new Container;\r\n$container->bind('app', $container);\r\n\r\n\/\/ Capsule\r\n$capsule = new Capsule;\r\n\r\n$capsule->addConnection([\r\n 'driver' =>'mysql',\r\n 'host' => $dbhost,\r\n 'database' => $dbname,\r\n 'username' => $dbuname,\r\n 'password' => $dbpass,\r\n 'charset' => 'utf8',\r\n 'collation' => 'utf8_unicode_ci',\r\n 'prefix' => $prefix.\"_\",\r\n]);\r\n\r\n$capsule->setEventDispatcher(new Dispatcher);\r\n\r\n\/\/ Make this Capsule instance available globally via static methods... (optional)\r\n$capsule->setAsGlobal();\r\n\r\n\/\/ Eloquent\r\n$capsule->bootEloquent();\r\n\r\n$container->instance(\"capsule\", $capsule);\r\n\r\n```\r\nWithout this line, \r\n\r\n**$capsule->setEventDispatcher(new Dispatcher);**\r\n\r\nthe code does not work.\r\n\r\n\r\n\r\n\r\nBest regards\r\n","issue_id":1660171593622,"origin_id":877800490,"user_origin_id":461705,"create_time":1626010259,"update_time":1626010342,"id":1669095100110,"updated_at":"2022-11-22T05:31:40.109000Z","created_at":"2022-11-22T05:31:40.109000Z"}] comment

I am sending the following array to the create() ``` array(3) { ["name"]=> string(4) "cat1" ["company_id"]=> int(1) ["children"]=> array(1) { array(2) { ["name"]=> string(4) "cat2" ["company_id"]=> int(1) } } }...

Laravel Nova support

[{"_id":"637c6a0a4b97542c9a2c16bf","body":"If you or someone sponsor this","issue_id":1660171593624,"origin_id":419792232,"user_origin_id":2094856,"create_time":1536557757,"update_time":1536557757,"id":1669097994709,"updated_at":"2022-11-22T06:19:54.708000Z","created_at":"2022-11-22T06:19:54.708000Z"},{"_id":"637c6a0a4b97542c9a2c16c0","body":"@lionskape, any update on this, did you get a solution?\r\n\r\nThis would be great if it worked on Laravel Nova..","issue_id":1660171593624,"origin_id":482582819,"user_origin_id":11265554,"create_time":1555077175,"update_time":1555077175,"id":1669097994713,"updated_at":"2022-11-22T06:19:54.713000Z","created_at":"2022-11-22T06:19:54.713000Z"},{"_id":"637c6a0a4b97542c9a2c16c1","body":"No.","issue_id":1660171593624,"origin_id":482597687,"user_origin_id":7500148,"create_time":1555079690,"update_time":1555079690,"id":1669097994717,"updated_at":"2022-11-22T06:19:54.716000Z","created_at":"2022-11-22T06:19:54.716000Z"},{"_id":"637c6a0a4b97542c9a2c16c2","body":"@lazychaser, kindly requesting for a solution in regards to Laravel Nova. ","issue_id":1660171593624,"origin_id":485810850,"user_origin_id":11265554,"create_time":1556027376,"update_time":1556027376,"id":1669097994719,"updated_at":"2022-11-22T06:19:54.719000Z","created_at":"2022-11-22T06:19:54.719000Z"},{"_id":"637c6a0a4b97542c9a2c16c3","body":"@kasirye feel free to send a PR \ud83d\ude04 ","issue_id":1660171593624,"origin_id":486111583,"user_origin_id":1227351,"create_time":1556092476,"update_time":1556092476,"id":1669097994722,"updated_at":"2022-11-22T06:19:54.721000Z","created_at":"2022-11-22T06:19:54.721000Z"},{"_id":"637c6a0a4b97542c9a2c16c4","body":"@kasirye what do you need? \r\n\r\n![image](https:\/\/user-images.githubusercontent.com\/382395\/75110378-d4af5980-562d-11ea-863b-7e67dfbd1c7f.png)\r\nIt is working out of the box ;)\r\n\r\nTrick to show the tree:\r\n```php\r\nText::make('Name')\r\n ->displayUsing(function($name, $resource){\r\n return str_repeat('  ', $resource->depth) . $name;\r\n })\r\n ->asHtml()\r\n ->onlyOnIndex(),\r\n```\r\n\r\n\r\nTo load the Resource List view with the right order:\r\n```php\r\n\/**\r\n * Build an \"index\" query for the given resource.\r\n *\r\n * @param \\Laravel\\Nova\\Http\\Requests\\NovaRequest $request\r\n * @param \\Illuminate\\Database\\Eloquent\\Builder $query\r\n * @return \\Illuminate\\Database\\Eloquent\\Builder\r\n *\/\r\n public static function indexQuery(NovaRequest $request, $query)\r\n {\r\n return $query->withDepth()->defaultOrder();\r\n }\r\n```","issue_id":1660171593624,"origin_id":590052955,"user_origin_id":382395,"create_time":1582453019,"update_time":1582453019,"id":1669097994726,"updated_at":"2022-11-22T06:19:54.725000Z","created_at":"2022-11-22T06:19:54.725000Z"},{"_id":"637c6a0a4b97542c9a2c16c5","body":"@lionskape I made it work using package https:\/\/github.com\/novius\/laravel-nova-order-nestedset-field and adding the following fields to the resource\r\n\r\n```php\r\nText::make('Name')\r\n ->displayUsing(function ($name, $resource) {\r\n return str_repeat('\u2192 ', $resource->depth) . $name;\r\n })->asHtml()->onlyOnIndex(),\r\n\r\nSelect::make('Parent Model', 'parent_id')\r\n ->options(function () {\r\n return ParentModel\r\n ::where('id', '!=', $this->id)\r\n ->get()\r\n ->reduce(function ($options, $model) {\r\n $options[$model['id']] = $model['name'];\r\n return $options;\r\n }, []);\r\n })\r\n ->nullable()\r\n ->onlyOnForms(),\r\n```\r\n\r\nThen adding the following to the resource file\r\n\r\n```php\r\n\/**\r\n * Build an \"index\" query for the given resource.\r\n *\r\n * @param \\Laravel\\Nova\\Http\\Requests\\NovaRequest $request\r\n * @param \\Illuminate\\Database\\Eloquent\\Builder $query\r\n * @return \\Illuminate\\Database\\Eloquent\\Builder\r\n *\/\r\npublic static function indexQuery(NovaRequest $request, $query)\r\n{\r\n return $query->withDepth()->defaultOrder();\r\n}\r\n\r\n```","issue_id":1660171593624,"origin_id":621012571,"user_origin_id":30062429,"create_time":1588141269,"update_time":1588141269,"id":1669097994732,"updated_at":"2022-11-22T06:19:54.732000Z","created_at":"2022-11-22T06:19:54.732000Z"},{"_id":"637c6a0a4b97542c9a2c16c6","body":"@cch504 Thanks for the example however I don't understand why you would need the package you mentioned?\r\n\r\nWould this not work without it?\r\n\r\nReason I ask is that package seems to be dead, and doesn't work on latest Nova (3.x)","issue_id":1660171593624,"origin_id":633568158,"user_origin_id":1567162,"create_time":1590412663,"update_time":1590412663,"id":1669097994736,"updated_at":"2022-11-22T06:19:54.735000Z","created_at":"2022-11-22T06:19:54.735000Z"},{"_id":"637c6a0a4b97542c9a2c16c7","body":"The solution by @thoresuenert works for me. However, using this resource as a `BelongsToMany` field on another resource creates an invalid SQL query. This might also apply to other types of relationship fields. I disabled this on relationship fields by replacing the `indexQuery` with:\r\n\r\n```php\r\npublic static function indexQuery(NovaRequest $request, $query)\r\n{\r\n return $request->viaRelationship()\r\n ? $query\r\n : $query->withDepth()->defaultOrder();\r\n}\r\n```","issue_id":1660171593624,"origin_id":876298212,"user_origin_id":44642427,"create_time":1625737737,"update_time":1625737891,"id":1669097994738,"updated_at":"2022-11-22T06:19:54.738000Z","created_at":"2022-11-22T06:19:54.738000Z"}] comment

Hello, it would be perfect, if you create Nova tool for your package.

How to fix the tree after adding nesting set through a migration?

[{"_id":"637c6d324b97542c9a2c19b1","body":"My additional workaround migration code using `id` as source value:\r\n\r\n**Without scoping:**\r\n```php\r\n\\App\\Unit::each(function (\\App\\Unit $unit) {\r\n $unit->setLft($unit->id * 2 - 1);\r\n $unit->setRgt($unit->id * 2);\r\n $unit->save();\r\n});\r\n```\r\n\r\n**With scoping:**\r\n```php\r\n\\App\\Unit::each(function (\\App\\Unit $unit) {\r\n $lowest = $unit->project->units->sortBy('id')->first()->id;\r\n\r\n $unit->setLft(($unit->id - $lowest + 1) * 2 - 1);\r\n $unit->setRgt(($unit->id - $lowest + 1) * 2);\r\n $unit->save();\r\n});\r\n```","issue_id":1660171593627,"origin_id":870460639,"user_origin_id":1951647,"create_time":1624961250,"update_time":1624961250,"id":1669098802445,"updated_at":"2022-11-22T06:33:22.445000Z","created_at":"2022-11-22T06:33:22.445000Z"}] comment

I need to add the nested set columns to an existing table. Adding the nested set columns with a migration like below works as intended, but the tree is in...