title: How to use where clause on data which is eager loaded in laravel 5?
body: <p>I want to display only the users who are admin and according to a search term which is entered in the searchbox</p>
  
  <p>I store the keyword first</p>
  
  <pre><code>$keyword = $request-&gt;get('search');
  </code></pre>
  
  <p>and then</p>
  
  <pre><code>$users = User::with('admin')-&gt;where('role', 'super_admin')
                      -&gt;where(function ($query) use($keyword){
                          $query-&gt;where('id', 'LIKE', "%$keyword%")
                          -&gt;orWhere('name', 'LIKE', "%$keyword%");
              })-&gt;paginate($perPage);
  </code></pre>
  
  <p>This works as im searching terms from main table that is <code>user</code> table</p>
  
  <p>But i also want to filter it using admin table columns as</p>
  
  <pre><code>$users = User::with('admin')-&gt;where('role', 'super_admin')
                      -&gt;where(function ($query) use($keyword){
                          $query-&gt;where('id', 'LIKE', "%$keyword%")
                          -&gt;orWhere('email', 'LIKE', "%$keyword%")
                          -&gt;orWhere('name', 'LIKE', "%$keyword%")
                          -&gt;orWhere($this-&gt;admin-&gt;status, 'LIKE', "%$keyword%");
              })-&gt;paginate($perPage);
  </code></pre>
  
  <p>This throws an error  <code>undefined property admin</code></p>
  
  <p>Due to this line <code>-&gt;orWhere($this-&gt;admin-&gt;status, 'LIKE', "%$keyword%");</code></p>
  
  <p>So how can i use admin column in filtering data</p>