From 56b18fc28bc2385a0e31b835982cf2b9bf78990a Mon Sep 17 00:00:00 2001 From: Thanos Charisoudis Date: Wed, 29 May 2019 16:15:41 +0300 Subject: [PATCH 1/4] Update NestedSet.php --- src/NestedSet.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/NestedSet.php b/src/NestedSet.php index 8ec8e02..4915973 100644 --- a/src/NestedSet.php +++ b/src/NestedSet.php @@ -36,13 +36,14 @@ class NestedSet * * @param \Illuminate\Database\Schema\Blueprint $table */ - public static function columns(Blueprint $table) + public static function columns(Blueprint $table, string $id = 'id') { - $table->unsignedInteger(self::LFT)->default(0); - $table->unsignedInteger(self::RGT)->default(0); - $table->unsignedInteger(self::PARENT_ID)->nullable(); + $table->unsignedBigInteger(self::LFT)->default(0); + $table->unsignedBigInteger(self::RGT)->default(0); + $table->unsignedBigInteger(self::PARENT_ID)->nullable(); $table->index(static::getDefaultColumns()); + $table->foreign(self::PARENT_ID)->references($id)->on($table->getTable())->onDelete('cascade'); } /** @@ -80,4 +81,4 @@ public static function isNode($node) return is_object($node) && in_array(NodeTrait::class, (array)$node); } -} \ No newline at end of file +} From 7d57225953a490ab5f991a999645198fd6d65a2d Mon Sep 17 00:00:00 2001 From: Thanos Charisoudis Date: Wed, 29 May 2019 16:21:20 +0300 Subject: [PATCH 2/4] Added id column as parameter to blueprint macro --- src/NestedSetServiceProvider.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/NestedSetServiceProvider.php b/src/NestedSetServiceProvider.php index b4516f7..525ca56 100644 --- a/src/NestedSetServiceProvider.php +++ b/src/NestedSetServiceProvider.php @@ -9,12 +9,12 @@ class NestedSetServiceProvider extends ServiceProvider { public function register() { - Blueprint::macro('nestedSet', function () { - NestedSet::columns($this); + Blueprint::macro('nestedSet', function (string $idColumn = 'id') { + NestedSet::columns($this, $idColumn); }); - Blueprint::macro('dropNestedSet', function () { - NestedSet::dropColumns($this); + Blueprint::macro('dropNestedSet', function (string $idColumn = 'id') { + NestedSet::dropColumns($this, $idColumn); }); } -} \ No newline at end of file +} From b4c75a4828507bcf8332e94d7edf37afb2df9440 Mon Sep 17 00:00:00 2001 From: Thanos Charisoudis Date: Wed, 29 May 2019 16:28:22 +0300 Subject: [PATCH 3/4] Added id column in param and foreign key in parent --- src/NestedSet.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/NestedSet.php b/src/NestedSet.php index 4915973..2f5ac6a 100644 --- a/src/NestedSet.php +++ b/src/NestedSet.php @@ -35,15 +35,16 @@ class NestedSet * Add default nested set columns to the table. Also create an index. * * @param \Illuminate\Database\Schema\Blueprint $table + * @param string $idColumn */ - public static function columns(Blueprint $table, string $id = 'id') + public static function columns(Blueprint $table, string $idColumn = 'id') { $table->unsignedBigInteger(self::LFT)->default(0); $table->unsignedBigInteger(self::RGT)->default(0); $table->unsignedBigInteger(self::PARENT_ID)->nullable(); $table->index(static::getDefaultColumns()); - $table->foreign(self::PARENT_ID)->references($id)->on($table->getTable())->onDelete('cascade'); + $table->foreign(self::PARENT_ID)->references($idColumn)->on($table->getTable())->onDelete('cascade'); } /** @@ -55,6 +56,7 @@ public static function dropColumns(Blueprint $table) { $columns = static::getDefaultColumns(); + $table->dropForeign(self::PARENT_ID); $table->dropIndex($columns); $table->dropColumn($columns); } From f3ace207dc95ba417762024fae5b5426c75d7b0f Mon Sep 17 00:00:00 2001 From: Thanos Charisoudis Date: Wed, 29 May 2019 16:29:16 +0300 Subject: [PATCH 4/4] Update NestedSetServiceProvider.php --- src/NestedSetServiceProvider.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/NestedSetServiceProvider.php b/src/NestedSetServiceProvider.php index 525ca56..740ef54 100644 --- a/src/NestedSetServiceProvider.php +++ b/src/NestedSetServiceProvider.php @@ -13,8 +13,8 @@ public function register() NestedSet::columns($this, $idColumn); }); - Blueprint::macro('dropNestedSet', function (string $idColumn = 'id') { - NestedSet::dropColumns($this, $idColumn); + Blueprint::macro('dropNestedSet', function () { + NestedSet::dropColumns($this); }); } }