title: search in a table and its relations in laravel
body: <p>I need to search for the code in the appointment table OR the patient name which is the appointment's relation. here is the code I reached so far but it is not working:</p>
  <pre><code>$lab = Lab::select('id', 'code')
  -&gt;Where('code', 'like', &quot;%{$search_query}%&quot;)
  -&gt;with(['patient' =&gt; function ($q) {
      $q-&gt;select('id', 'avatar', DB::raw('CONCAT(first_Name, &quot; &quot;, second_Name) AS name')
      -&gt;where('name', 'like', &quot;%{$search_query}%&quot;)
      -&gt;orWhereRaw(&quot;concat(first_name, ' ', second_name) like '%$search_query%' &quot;)
  );}])
  -&gt;limit(5)
  -&gt;get();      
  </code></pre>