What are the reordering columns on laravel-backpack?

允我心安 提交于 2020-01-04 02:33:11

问题


In the official documentation, the following columns are mentioned :

  • parent_id
  • lft
  • rgt
  • depth

I haven't found any explanation of their types in the documentation. Could someone help me and tell me what they are ?

I also want to know if they are all mandatory if I only want to reorder a list of items (I don't need any nesting).

Edit: As this question is quite popular, I've updated the documentation with the correct info.


回答1:


The reordering id columns should be integer or INT(10) if you're not using a migration.

Unfortunately they're all mandatory, yes. But if you're on a very strict DB schema, you could eliminate all of them except the "lft" column by adding this method to your EntityCrudController (basically overwriting the one in Backpack\CRUD\app\Http\Controllers\CrudFeatures\Reorder):

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';
}


来源:https://stackoverflow.com/questions/40334901/what-are-the-reordering-columns-on-laravel-backpack

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!