I.Jokhadze
I.Jokhadze

Reputation: 33

Laravel Eloquent Json Column Update Overwrites Old Data

I have two step registration on my website, and I'm trying to update user information data which I have in the data column. The first step is the username and last name and on second step I'm trying to insert additional data into my JSON column. This is my step two update:

$user->update([
       'data' => [
           'add_info' => json_encode($new_array_of_data)
    ]);

But this overwrites old data which I inserted on step one.

Upvotes: 0

Views: 1016

Answers (1)

Lio
Lio

Reputation: 1503

To update json type column, you need to use the following syntax:

$user->update(['data->add_info' => $your_data]);

According to: New JSON-column where() and update() syntax in Laravel 5.3

Upvotes: 1

Related Questions