Search code examples
phplaravellaravel-backpacklaravel-9

Is there a way to store fake attributes as an array instead of JSON?


I am using Laravel Backpack's fake field attribute to store clicked checkboxes into the database. But I don't want it stored as JSON but as an array for example:

Not:

{ "key" : "value }

But as:

[ "value" ]

Here is more context: https://backpackforlaravel.com/docs/5.x/crud-fields#optional-fake-field-attributes-stores-fake-attributes-as-json-in

Here is an example code snippet

protected function setupUpdateOperation()
{
    // The data for the checkboxes values
    $roles = Role::all();

    foreach ($roles as $role) {
        CRUD::field('checkbox_' . $role->id)->type('checkbox')->label($role->description)->fake(true)->store_in('checkboxes_data');
    }
}

Let me know if you need more information!


Solution

  • Found it! I just have to override the update method.

    For example:

    public function update($id)
    {
        // Logic after update is done.
    }