Answer the question
In order to leave comments, you need to log in
How to add data to the existing ones in a JSON format cell?
Laravel 5.4
MySQL 5.7
The task was to save NickName WE of users in the database who decided to participate in the draw.
It is most convenient to store them in an array or in a cell in JSON format.
Problem:
If there is already 1 nickname in a cell, how can I add a second one to it?
I did this:
I got the old value and assigned the new one, but the non-names began to merge, I had to separate them with '|' and when fetching using explode(), remove the separator and get an array of names.
$slash = '|';
$test->party = $test->party.= $slash .= $lottery->nickname;
$test->sum = $test->sum + 1;
$test->save();
Answer the question
In order to leave comments, you need to log in
and here explode if you use json.
json_encode() -> json_decode()
serialize() -> unserialize()
It is most convenient to store them in an array or in a cell in JSON format.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question