title: Laravel search in json for value in query where
body: <p>I'm trying to build tags system.
  In my database, I have table <code>topics</code> with column <code>tags</code>. Tags are a JSON object.</p>
  
  <p>My route: </p>
  
  <pre><code>Route::get('t/{tag}', 'myController@tag')-&gt;name('tag');
  
  public function tag( $tag )
  {
      return view('tags.tag', ['tag' =&gt; $tag, 'topics' =&gt; DB::table('topics')-&gt;get()]);
  }
  </code></pre>
  
  <p>And then:</p>
  
  <pre><code>@foreach ($topics as $topic)
      @if (in_array($tag, json_decode($topic-&gt;tags, true)))
      &lt;tr&gt;
          &lt;td class="col-md-6 col-sm-6"&gt;
              &lt;a href="#" title=""&gt;
                  &lt;strong&gt;{{ $topic-&gt;topic_name }}&lt;/strong&gt;
              &lt;/a&gt;    
          &lt;/td&gt;
          &lt;td class="col-md-1 col-sm-1 text-right"&gt;
              @foreach (json_decode($topic-&gt;tags) as $tag)
                  &lt;span class="badge badge-primary"&gt;{{ $tag }}&lt;/span&gt;
              @endforeach
          &lt;/td&gt;
      &lt;/tr&gt;
      @endif
   @endforeach
  </code></pre>
  
  <p>I know this is not a perfect solution and I need to use that if in a query. How can I do this? Thanks in advance. P.S I know about '->where('topics->tags', '..')</p>
  
  <p>But my MySQL is older than 5.7 and I can't use these new functions. Any suggestions?</p>