laravel-backpack 上的重新排序列是什么?
What are the reordering columns on laravel-backpack?
在the official documentation中,提到了以下列:
- parent_id
- lft
- rgt
- 深度
我没有在文档中找到关于它们类型的任何解释。谁能帮我告诉我它们是什么?
我还想知道如果我只想重新排序项目列表(我不需要任何嵌套),它们是否都是强制性的。
编辑:由于这个问题很受欢迎,我 updated the documentation with the correct info。
重新排序 ID 列应该是 integer
或 INT(10)(如果您没有使用迁移)。
不幸的是,它们都是强制性的,是的。但是,如果您使用的是非常严格的数据库架构,则可以通过将此方法添加到您的 EntityCrudController(基本上覆盖 Backpack\CRUD\app\Http\Controllers\CrudFeatures\Reorder
中的方法)来消除除 "lft" 列之外的所有其他架构:
public function saveReorder()
{
$this->crud->hasAccessOrFail('reorder');
$all_entries = \Request::input('tree');
if (count($all_entries)) {
$count = 0;
foreach ($all_entries as $key => $entry) {
if ($entry['item_id'] != '' && $entry['item_id'] != null) {
$item = $this->crud->model->find($entry['item_id']);
$item->lft = empty($entry['left']) ? null : $entry['left'];
$item->save();
$count++;
}
}
} else {
return false;
}
return 'success for '.$count.' items';
}
在the official documentation中,提到了以下列:
- parent_id
- lft
- rgt
- 深度
我没有在文档中找到关于它们类型的任何解释。谁能帮我告诉我它们是什么?
我还想知道如果我只想重新排序项目列表(我不需要任何嵌套),它们是否都是强制性的。
编辑:由于这个问题很受欢迎,我 updated the documentation with the correct info。
重新排序 ID 列应该是 integer
或 INT(10)(如果您没有使用迁移)。
不幸的是,它们都是强制性的,是的。但是,如果您使用的是非常严格的数据库架构,则可以通过将此方法添加到您的 EntityCrudController(基本上覆盖 Backpack\CRUD\app\Http\Controllers\CrudFeatures\Reorder
中的方法)来消除除 "lft" 列之外的所有其他架构:
public function saveReorder()
{
$this->crud->hasAccessOrFail('reorder');
$all_entries = \Request::input('tree');
if (count($all_entries)) {
$count = 0;
foreach ($all_entries as $key => $entry) {
if ($entry['item_id'] != '' && $entry['item_id'] != null) {
$item = $this->crud->model->find($entry['item_id']);
$item->lft = empty($entry['left']) ? null : $entry['left'];
$item->save();
$count++;
}
}
} else {
return false;
}
return 'success for '.$count.' items';
}