Orange Lux
Orange Lux

Reputation: 2037

What are the reordering columns on laravel-backpack?

In the official documentation, the following columns are mentioned :

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.

Upvotes: 3

Views: 2225

Answers (1)

tabacitu
tabacitu

Reputation: 6223

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

Upvotes: 6

Related Questions