Laravel Backpack checklist array storing ids instead of name values

Viewed 50
2 Answers

You should be able to give an array to the “options” attribute, instead of specifying “entity”, “attribute”, “model”, “pivot”.

The array elements should be [value => label], where the value is what will be stored in the db, the label is what is shown next to the checkbox.

I solved this by creating a pivot table between merch and sizes and then changing the type of the column size.

$this->crud->addColumns( [
        [
            'label' => 'Sizes',
            'type' => "select_multiple",
            'entity' => 'sizes', // the method that defines the relationship in your Model
            'name' => 'sizes',
            'attribute' => "name", // foreign key attribute that is shown to user
            'model' => "App\Models\Size",
            'pivot'     => true,
        ],
    ]);
Related