Skip to content
Advertisement

Laravel Backpack checklist array storing ids instead of name values

I made a checklist with the possible sizes of a certain product but its storing the ids instead of the specific size.

This is the size field display.

I have the size field code like this:

CRUD::addField([
        'label'     => 'Size',
        'type'      => 'checklist',
        'name'      => 'size',
        'entity'    => 'sizes',
        'attribute' => 'name',
        'model'     => 'AppModelsSize',
        'pivot'     => false,
    ]);

How do I change it to store the size’s name?

Advertisement

Answer

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' => "AppModelsSize",
            'pivot'     => true,
        ],
    ]);
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement