Skip to content

Commit 65b08fb

Browse files
committed
Add blueprint macros
1 parent 6151674 commit 65b08fb

File tree

4 files changed

+46
-2
lines changed

4 files changed

+46
-2
lines changed

CHANGELOG.markdown

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
### 4.3.1
2+
* Support Laravel 5.6
3+
* Added `nestedSet` and `dropNestedSet` blueprint macros
4+
15
### 4.3.0
26
* Support Laravel 5.5
37
* Added `fixSubtree` and `rebuildSubtree` methods

README.markdown

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
This is a Laravel 4-5 package for working with trees in relational databases.
88

9-
* **Laravel 5.5** is supported since v4.3
9+
* **Laravel 5.5, 5.6** is supported since v4.3
1010
* **Laravel 5.2, 5.3, 5.4** is supported since v4
1111
* **Laravel 5.1** is supported in v3
1212
* **Laravel 4** is supported in v2
@@ -627,7 +627,21 @@ composer require kalnoy/nestedset
627627

628628
#### The schema
629629

630-
You can use a method to add needed columns with default names:
630+
For Laravel 5.5 and above users:
631+
632+
```php
633+
Schema::create('table', function (Blueprint $table) {
634+
...
635+
$table->nestedSet();
636+
});
637+
638+
// To drop columns
639+
Schema::table('table', function (Blueprint $table) {
640+
$table->dropNestedSet();
641+
});
642+
```
643+
644+
For prior Laravel versions:
631645

632646
```php
633647
...

composer.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@
3434
"extra": {
3535
"branch-alias": {
3636
"dev-master": "v4.2.x-dev"
37+
},
38+
39+
"laravel": {
40+
"providers": [
41+
"Kalnoy\\Nestedset\\NestedSetServiceProvider"
42+
]
3743
}
3844
}
3945
}

src/NestedSetServiceProvider.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace Kalnoy\Nestedset;
4+
5+
use Illuminate\Database\Schema\Blueprint;
6+
use Illuminate\Support\ServiceProvider;
7+
8+
class NestedSetServiceProvider extends ServiceProvider
9+
{
10+
public function register()
11+
{
12+
Blueprint::macro('nestedSet', function () {
13+
NestedSet::columns($this);
14+
});
15+
16+
Blueprint::macro('dropNestedSet', function () {
17+
NestedSet::dropColumns($this);
18+
});
19+
}
20+
}

0 commit comments

Comments
 (0)