$skill = new Skill;
says create a new skill.
You have made life hard by saving json string and not saving the actual skill.
Anyway, whatever, have a look at findOrCreate to get the previous skill for the user and overwrite it.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
How do you save, update and retrieve an array from and to the database?
I have a skills table with 3 fields: id, user_id, skill_name
At the moment, when I select skills from a chosen js multi-select field, it gets inserted in the database and it looks like this
a:2:{i:0;s:3:"php";i:1;s:5:"mysql";}
However, if I went back and selected new skills including skills I have already selected, a new record in the table will be created with the new skills along side the skills I've selected earlier. My table will look something like this, as you can see mysql is present twice.

Instead, I need it to update the table row of the user instead of creating a new row with the same values.
How may I achieve that? Also, am I doing this thing correctly? Is that how you're supposed to save an array to the database?
App\User
public function skill() {
return $this->hasMany('App\Skill');
}
App\Skill
public function user() {
return $this->belongsTo('App\User');
}
UserController
$skills = $request->input('skills');
$json_skills = serialize($skills);
if($skills) {
$skill = new Skill;
$skill->user_id = Auth::user()->id;
$skill->skill_name = $json_skills;
$user->skill()->save($skill);
}
Please or to participate in this conversation.