6
6
7
7
This is a Laravel 4-5 package for working with trees in relational databases.
8
8
9
- * ** Laravel 5.2** is supported since v4
9
+ * ** Laravel 5.2, 5.3 ** is supported since v4
10
10
* ** Laravel 5.1** is supported in v3
11
11
* ** Laravel 4** is supported in v2
12
12
@@ -42,7 +42,7 @@ a way to effectively store hierarchical data in a relational table. From wikiped
42
42
### Applications
43
43
44
44
NSM shows good performance when tree is updated rarely. It is tuned to be fast for
45
- getting related nodes. It'is ideally suited for building multi-depth menu or
45
+ getting related nodes. It'is ideally suited for building multi-depth menu or
46
46
categories for shop.
47
47
48
48
Documentation
@@ -62,7 +62,7 @@ Node has following relationships that are fully functional and can be eagerly lo
62
62
### Inserting nodes
63
63
64
64
Moving and inserting nodes includes several database queries, so __ transaction is
65
- automatically started__ when node is saved. It is safe to use global transaction
65
+ automatically started__ when node is saved. It is safe to use global transaction
66
66
if you work with several models.
67
67
68
68
Another important note is that __ structural manipulations are deferred__ until you
@@ -148,7 +148,7 @@ $parent->prependNode($node);
148
148
149
149
You can make ` $node ` to be a neighbor of the ` $neighbor ` node using following methods:
150
150
151
- * ` $neighbor ` must exists, target node can be fresh. If target node exists,
151
+ * ` $neighbor ` must exists, target node can be fresh. If target node exists,
152
152
it will be moved to the new position and parent will be changed if it's required.*
153
153
154
154
``` php
@@ -169,11 +169,11 @@ When using static method `create` on node, it checks whether attributes contains
169
169
``` php
170
170
$node = Category::create([
171
171
'name' => 'Foo',
172
-
172
+
173
173
'children' => [
174
174
[
175
175
'name' => 'Bar',
176
-
176
+
177
177
'children' => [
178
178
[ 'name' => 'Baz' ],
179
179
],
@@ -225,7 +225,7 @@ to the current category.
225
225
// #1 Using accessor
226
226
$result = $node->getAncestors();
227
227
228
- // #2 Using a query
228
+ // #2 Using a query
229
229
$result = $node->ancestors()->get();
230
230
231
231
// #3 Getting ancestors by primary key
@@ -270,7 +270,7 @@ To get only next siblings:
270
270
// Get a sibling that is immediately after the node
271
271
$result = $node->getNextSibling();
272
272
273
- // Get all siblings that are after the node
273
+ // Get all siblings that are after the node
274
274
$result = $node->getNextSiblings();
275
275
276
276
// Get all siblings using a query
@@ -283,7 +283,7 @@ To get previous siblings:
283
283
// Get a sibling that is immediately before the node
284
284
$result = $node->getPrevSibling();
285
285
286
- // Get all siblings that are before the node
286
+ // Get all siblings that are before the node
287
287
$result = $node->getPrevSiblings();
288
288
289
289
// Get all siblings using a query
@@ -507,10 +507,10 @@ It will return an array with following keys:
507
507
doesn't correspond to ` lft ` and ` rgt ` values
508
508
- ` missing_parent ` -- the number of nodes that have ` parent_id ` pointing to
509
509
node that doesn't exists
510
-
510
+
511
511
#### Fixing tree
512
512
513
- Since v3.1 tree can now be fixed. Using inheritance info from ` parent_id ` column,
513
+ Since v3.1 tree can now be fixed. Using inheritance info from ` parent_id ` column,
514
514
proper ` _lft ` and ` _rgt ` values are set for every node.
515
515
516
516
``` php
@@ -521,7 +521,7 @@ Node::fixTree();
521
521
522
522
Imagine you have ` Menu ` model and ` MenuItems ` . There is a one-to-many relationship
523
523
set up between these models. ` MenuItem ` has ` menu_id ` attribute for joining models
524
- together. ` MenuItem ` incorporates nested sets. It is obvious that you would want to
524
+ together. ` MenuItem ` incorporates nested sets. It is obvious that you would want to
525
525
process each tree separately based on ` menu_id ` attribute. In order to do so, you
526
526
need to specify this attribute as scope attribute:
527
527
@@ -541,7 +541,7 @@ MenuItem::descendantsOf($id)->get(); // WRONG: returns nodes from other scope
541
541
MenuItem::scoped([ 'menu_id' => 5 ])->fixTree();
542
542
```
543
543
544
- When requesting nodes using model instance, scopes applied automatically based
544
+ When requesting nodes using model instance, scopes applied automatically based
545
545
on the attributes of that model. See examples:
546
546
547
547
``` php
@@ -556,7 +556,7 @@ To get scoped query builder using instance:
556
556
$node->newScopedQuery();
557
557
```
558
558
559
- Note, that scoping is not required when retrieving model by primary key
559
+ Note, that scoping is not required when retrieving model by primary key
560
560
(since the key is unique):
561
561
562
562
``` php
@@ -570,7 +570,7 @@ Requirements
570
570
- PHP >= 5.4
571
571
- Laravel >= 4.1
572
572
573
- It is highly suggested to use database that supports transactions (like MySql's InnoDb)
573
+ It is highly suggested to use database that supports transactions (like MySql's InnoDb)
574
574
to secure a tree from possible corruption.
575
575
576
576
Installation
@@ -654,7 +654,7 @@ $table->unsignedInteger('_lft');
654
654
$table->unsignedInteger('_rgt');
655
655
```
656
656
657
- After [ setting up your model] ( #the-model ) you only need to fix the tree to fill
657
+ After [ setting up your model] ( #the-model ) you only need to fix the tree to fill
658
658
` _lft ` and ` _rgt ` columns:
659
659
660
660
``` php
0 commit comments