title: Laravel Eloquent is there a way to update Mysql json datatype key only?
body: <p>I have data in MySQL db, table 'user', column 'attributes' with json type as follow :</p>
  
  <pre><code>{"hp": {"remaining": 10, "total": 10}, "mp": {"remaining": 5, "total": 5}}
  </code></pre>
  
  <p>I want to update hp->remaining to 9 without updating the whole json but just the key</p>
  
  <p>1st method :</p>
  
  <pre><code>$user = Users::find(1)-&gt;firstOrFail();
  $user-&gt;attributes-&gt;hp-&gt;remaining = 9;
  $user-&gt;save();
  </code></pre>
  
  <p>it failed saying Indirect modification of overloaded property App\Models\Users::$attributes has no effect</p>
  
  <p>2nd method :</p>
  
  <pre><code>$user = Users::find(1)-&gt;firstOrFail();
  $user-&gt;attributes = json_encode(array('hp' =&gt; array('remaining' =&gt; 9)));
  $user-&gt;save();
  </code></pre>
  
  <p>it didn't have any errors but it failed because it updated the whole json attributes and lost 'hp->total' key and all mp, thus became</p>
  
  <pre><code>{"hp": {"remaining": 9}}
  </code></pre>
  
  <p>I know I can just replace the whole json with updated key like: </p>
  
  <pre><code>$user = Users::find(1)-&gt;firstOrFail();
  $user-&gt;attributes = json_encode(array(
                                        'hp' =&gt; array('remaining' =&gt; 9, 'total' =&gt; 10), 
                                        'mp' =&gt; array('remaining' =&gt; 5, 'total' =&gt; 5)
                                       ));
  $user-&gt;save();
  </code></pre>
  
  <p>However is there a way to update just the key?</p>