Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Guide the reader about how to actually use Reorder Operation #616

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion 3.5/crud-fields.md
Original file line number Diff line number Diff line change
Expand Up @@ -962,7 +962,7 @@ Input preview:
<a name="select2-nested"></a>
### 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;

Expand Down
2 changes: 1 addition & 1 deletion 3.6/crud-fields.md
Original file line number Diff line number Diff line change
Expand Up @@ -970,7 +970,7 @@ Input preview:
<a name="select2-nested"></a>
### 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;

Expand Down
2 changes: 1 addition & 1 deletion 4.0/crud-fields.md
Original file line number Diff line number Diff line change
Expand Up @@ -1022,7 +1022,7 @@ Input preview:
<a name="select2-nested"></a>
### 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;

Expand Down
2 changes: 1 addition & 1 deletion 4.1/crud-fields.md
Original file line number Diff line number Diff line change
Expand Up @@ -1450,7 +1450,7 @@ Input preview:
<a name="select2-nested"></a>
### 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;

Expand Down
2 changes: 1 addition & 1 deletion 5.x/crud-fields.md
Original file line number Diff line number Diff line change
Expand Up @@ -2186,7 +2186,7 @@ Input preview:
<a name="select2-nested"></a>
### select2_nested <span class="badge badge-pill badge-info">PRO</span>

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;

Expand Down
2 changes: 1 addition & 1 deletion 6.x/crud-fields.md
Original file line number Diff line number Diff line change
Expand Up @@ -2194,7 +2194,7 @@ Input preview:
<a name="select2-nested"></a>
### select2_nested <span class="badge badge-pill badge-info">PRO</span>

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;

Expand Down
43 changes: 40 additions & 3 deletions 6.x/crud-operation-reorder.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,28 @@ This operation allows your admins to reorder & nest entries.
<a name="requirements"></a>
## 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

Expand All @@ -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
<?php

class Category extends Model
{
public function children()
{
return $this->hasMany(
\App\Models\Category::class,
'parent_id'
);
}
}

```

<a name="how-to-use"></a>
## How to Use
Expand Down
Loading