title: Search in Json column with Laravel
body: <p>In my emails table, I have a column named <code>To</code> with column-type <code>Json</code>. This is how values are stored:</p>
  
  <pre><code>[
      {
          "emailAddress": {
              "name": "Test", 
              "address": "test@example.com"
          }
      }, 
      {
          "emailAddress": {
              "name": "Test 2", 
              "address": "test2@example.com"
          }
      }
  ]
  </code></pre>
  
  <p>Now I want a collection of all emails sent to "test@example.com". I tried:</p>
  
  <pre><code>DB::table('emails')-&gt;whereJsonContains('to-&gt;emailAddress-&gt;address', 'test@example.com')-&gt;get();
  </code></pre>
  
  <p>(see <a href="https://laravel.com/docs/5.7/queries#json-where-clauses" rel="noreferrer">https://laravel.com/docs/5.7/queries#json-where-clauses</a>)
  but I do not get a match. Is there a better way to search using Laravel (Eloquent)?</p>
  
  <p>In the debugbar, I can see that this query is "translated" as:</p>
  
  <pre><code>select * from `emails` where json_contains(`to`-&gt;'$."emailAddress"."address"', '\"test@example.com\"'))
  </code></pre>