From 203320865515402f44012611eea2869403183c80 Mon Sep 17 00:00:00 2001 From: Don Cadavona Date: Mon, 9 Dec 2024 21:57:34 +0800 Subject: [PATCH] Add link to the Reorder operation in select2_nested docs. Add sample children relationship and migration. --- 3.5/crud-fields.md | 2 +- 3.6/crud-fields.md | 2 +- 4.0/crud-fields.md | 2 +- 4.1/crud-fields.md | 2 +- 5.x/crud-fields.md | 2 +- 6.x/crud-fields.md | 2 +- 6.x/crud-operation-reorder.md | 43 ++++++++++++++++++++++++++++++++--- 7 files changed, 46 insertions(+), 9 deletions(-) diff --git a/3.5/crud-fields.md b/3.5/crud-fields.md index 187debc8..24435e0e 100644 --- a/3.5/crud-fields.md +++ b/3.5/crud-fields.md @@ -962,7 +962,7 @@ Input preview: ### select2_nested -Display a select2 with the values ordered hierarchically and indented, for an entity where you use Reorder. Please mind that the connected model needs: +Display a select2 with the values ordered hierarchically and indented, for an entity where you use [Reorder](https://backpackforlaravel.com/docs/3.5/crud-operation-reorder). Please mind that the connected model needs: - a ```children()``` relationship pointing to itself; - the usual ```lft```, ```rgt```, ```depth``` attributes; diff --git a/3.6/crud-fields.md b/3.6/crud-fields.md index e2e889b1..acfc1c06 100644 --- a/3.6/crud-fields.md +++ b/3.6/crud-fields.md @@ -970,7 +970,7 @@ Input preview: ### select2_nested -Display a select2 with the values ordered hierarchically and indented, for an entity where you use Reorder. Please mind that the connected model needs: +Display a select2 with the values ordered hierarchically and indented, for an entity where you use [Reorder](https://backpackforlaravel.com/docs/3.6/crud-operation-reorder). Please mind that the connected model needs: - a ```children()``` relationship pointing to itself; - the usual ```lft```, ```rgt```, ```depth``` attributes; diff --git a/4.0/crud-fields.md b/4.0/crud-fields.md index d8dca2fb..63780f99 100644 --- a/4.0/crud-fields.md +++ b/4.0/crud-fields.md @@ -1022,7 +1022,7 @@ Input preview: ### select2_nested -Display a select2 with the values ordered hierarchically and indented, for an entity where you use Reorder. Please mind that the connected model needs: +Display a select2 with the values ordered hierarchically and indented, for an entity where you use [Reorder](https://backpackforlaravel.com/docs/4.0/crud-operation-reorder). Please mind that the connected model needs: - a ```children()``` relationship pointing to itself; - the usual ```lft```, ```rgt```, ```depth``` attributes; diff --git a/4.1/crud-fields.md b/4.1/crud-fields.md index 3a5ff7dd..2dec1a49 100644 --- a/4.1/crud-fields.md +++ b/4.1/crud-fields.md @@ -1450,7 +1450,7 @@ Input preview: ### select2_nested -Display a select2 with the values ordered hierarchically and indented, for an entity where you use Reorder. Please mind that the connected model needs: +Display a select2 with the values ordered hierarchically and indented, for an entity where you use [Reorder](https://backpackforlaravel.com/docs/4.1/crud-operation-reorder). Please mind that the connected model needs: - a ```children()``` relationship pointing to itself; - the usual ```lft```, ```rgt```, ```depth``` attributes; diff --git a/5.x/crud-fields.md b/5.x/crud-fields.md index 648053a7..99bb8994 100644 --- a/5.x/crud-fields.md +++ b/5.x/crud-fields.md @@ -2186,7 +2186,7 @@ Input preview: ### select2_nested PRO -Display a select2 with the values ordered hierarchically and indented, for an entity where you use Reorder. Please mind that the connected model needs: +Display a select2 with the values ordered hierarchically and indented, for an entity where you use [Reorder](https://backpackforlaravel.com/docs/5.x/crud-operation-reorder). Please mind that the connected model needs: - a ```children()``` relationship pointing to itself; - the usual ```lft```, ```rgt```, ```depth``` attributes; diff --git a/6.x/crud-fields.md b/6.x/crud-fields.md index 468aa21b..399363dc 100644 --- a/6.x/crud-fields.md +++ b/6.x/crud-fields.md @@ -2194,7 +2194,7 @@ Input preview: ### select2_nested PRO -Display a select2 with the values ordered hierarchically and indented, for an entity where you use Reorder. Please mind that the connected model needs: +Display a select2 with the values ordered hierarchically and indented, for an entity where you use [Reorder](https://backpackforlaravel.com/docs/6.x/crud-operation-reorder). Please mind that the connected model needs: - a ```children()``` relationship pointing to itself; - the usual ```lft```, ```rgt```, ```depth``` attributes; diff --git a/6.x/crud-operation-reorder.md b/6.x/crud-operation-reorder.md index a0eab207..d90849bf 100644 --- a/6.x/crud-operation-reorder.md +++ b/6.x/crud-operation-reorder.md @@ -12,7 +12,28 @@ This operation allows your admins to reorder & nest entries. ## Requirements -Your model should have the following integer fields, with a default value of 0: ```parent_id```, ```lft```, ```rgt```, ```depth```. The names are optional, you can change them in the ```setupReorderOperation()``` method. +Your model should have the following integer fields, with a default value of 0: `parent_id`, `lft`, `rgt`, `depth`. Additionally, the `parent_id` field has to be nullable. Here is an example migration: + +```php +public function up(): void +{ + Schema::create('categories', function (Blueprint $table) { + $table->increments('id'); + $table->string('name')->unique(); + + $table->unsignedInteger('parent_id') + ->nullable() + ->default(null); + $table->unsignedInteger('lft')->default(0); + $table->unsignedInteger('rgt')->default(0); + $table->unsignedInteger('depth')->default(0); + + $table->timestamps(); + }); +} +``` + +The names are optional, you can change them in the ```setupReorderOperation()``` method. ```php @@ -25,9 +46,25 @@ protected function setupReorderOperation() 'depth' => 'deep', ]); } -``` +``` -Additionally, the `parent_id` field has to be nullable. +Then, define the `children` relationship of the model that points to itself: + +```php +hasMany( + \App\Models\Category::class, + 'parent_id' + ); + } +} + +``` ## How to Use