2 of 2
added 330 characters in body

How to append unique ID to a json array - OctoberCMS / Laravel

OctoberCMS BackendForm-Widget "Repeater" stores my data as an array in the database which looks like so:

    {
    "topic":"title",
    "topic_description":"description",
    }
    {
    "topic":"title",
    "topic_description":"description",
    }

I need to add a unique ID to each array so the json looks like this:

    {   
    "topic_id":"1",
    "topic":"title",
    "topic_description":"description",
    }  
    {   
    "topic_id":"2",
    "topic":"title",
    "topic_description":"description",
    }

I have added this formBeforeSave function to my controller:

public function formBeforeSave($model)
    {

        $model->topics = array_map(array($model, 'topics'), function ($topic) {
         $topic['id'] = uniqid();
        });
    }

But when trying to save the form OctoberCMS throws this error:

“array_map(): Argument #2 should be an array”

Adding this to the controller instead:

public function formBeforeSave($model)
{
    $model->topics = array_map($model->topics, function ($topic) {
         $topic['id'] = uniqid();
    });
}

Throws the error:

array_map() expects parameter 1 to be a valid callback, array must have exactly two members

Has anyone experienced this and found a solution he/she could share please?