Answer the question
In order to leave comments, you need to log in
How to add data to a table field, adding to what is already there?
Through the model I write data to the table. Rather, I update one field. The array is stored in a string field. And so, how can you update this field by adding another array to this array? It does not matter whether the same or different values \u200b\u200bwill come, before what is there to add.
Answer the question
In order to leave comments, you need to log in
As I understand it, if you save an array in the string field in the database, then you most likely encode this array into JSON to write it as a string. Right?
As an option:
$array = json_decode($model->field); // декодируем string в array
$data = ['массив которым хотим дополнить', 'поле'];
$array = array_merge($array, $data); // объединяем массивы
$model->field = json_encode($array); // кодируем и сохраняем
$model->save();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question