Skip to content

Commit 247da41

Browse files
committed
Fixed compat issues to allow v4.1 rather than 5.0
1 parent 5c88c2a commit 247da41

File tree

5 files changed

+49
-23
lines changed

5 files changed

+49
-23
lines changed

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
"extra": {
2828
"branch-alias": {
29-
"dev-master": "v5.0.x-dev"
29+
"dev-master": "v4.1.x-dev"
3030
}
3131
}
3232
}

src/NestedSet.php

+10
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@ class NestedSet
2121
*/
2222
const PARENT_ID = 'parent_id';
2323

24+
/**
25+
* Insert direction.
26+
*/
27+
const BEFORE = 1;
28+
29+
/**
30+
* Insert direction.
31+
*/
32+
const AFTER = 2;
33+
2434
/**
2535
* Add default nested set columns to the table. Also create an index.
2636
*

src/Node.php

+32-1
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,40 @@
55
use Illuminate\Database\Eloquent\Model;
66

77
/**
8-
* @deprecated since 5.0
8+
* @deprecated since 4.1
99
*/
1010
class Node extends Model
1111
{
1212
use NodeTrait;
13+
14+
const LFT = NestedSet::LFT;
15+
16+
const RGT = NestedSet::RGT;
17+
18+
const PARENT_ID = NestedSet::PARENT_ID;
19+
20+
/**
21+
* @return string
22+
*/
23+
public function getParentIdName()
24+
{
25+
return static::PARENT_ID;
26+
}
27+
28+
/**
29+
* @return string
30+
*/
31+
public function getLftName()
32+
{
33+
return static::LFT;
34+
}
35+
36+
/**
37+
* @return string
38+
*/
39+
public function getRgtName()
40+
{
41+
return static::RGT;
42+
}
43+
1344
}

src/NodeTrait.php

+5-19
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,6 @@
1212

1313
trait NodeTrait
1414
{
15-
/**
16-
* Insert direction.
17-
*
18-
* @var string
19-
*/
20-
public static $before = 'before';
21-
22-
/**
23-
* Insert direction.
24-
*
25-
* @var string
26-
*/
27-
public static $after = 'after';
28-
2915
/**
3016
* Pending operation.
3117
*
@@ -297,20 +283,20 @@ public function descendants()
297283
/**
298284
* Get query for siblings of the node.
299285
*
300-
* @param static::$after|static::$before|null $dir
286+
* @param mixed $dir
301287
*
302288
* @return QueryBuilder
303289
*/
304290
public function siblings($dir = null)
305291
{
306292
switch ($dir)
307293
{
308-
case static::$after:
294+
case NestedSet::AFTER:
309295
$query = $this->nextNodes();
310296

311297
break;
312298

313-
case static::$before:
299+
case NestedSet::BEFORE:
314300
$query = $this->prevNodes();
315301

316302
break;
@@ -335,7 +321,7 @@ public function siblings($dir = null)
335321
*/
336322
public function nextSiblings()
337323
{
338-
return $this->siblings(static::$after);
324+
return $this->siblings(NestedSet::AFTER);
339325
}
340326

341327
/**
@@ -345,7 +331,7 @@ public function nextSiblings()
345331
*/
346332
public function prevSiblings()
347333
{
348-
return $this->siblings(static::$before);
334+
return $this->siblings(NestedSet::BEFORE);
349335
}
350336

351337
/**

tests/models/Category.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22

33
use \Illuminate\Database\Eloquent\Model;
44

5-
class Category extends Model {
5+
class Category extends \Kalnoy\Nestedset\Node {
66

77
use \Illuminate\Database\Eloquent\SoftDeletes;
8-
use \Kalnoy\Nestedset\NodeTrait;
98

109
protected $fillable = array('name', 'parent_id');
1110

0 commit comments

Comments
 (0)