title: Laravel repository pattern add query
body: <p>I am making a repository pattern in Laravel, and I have made an <code>AbstractRepository</code> class which is extended by any repository to get the most used CRUD methods which can be shared.</p>
  
  <p>Now I can extend the main functionality by adding additional methods to concrete repositories if I need some more complex queries. </p>
  
  <p>For example:</p>
  
  <pre><code>public function eagerWhere($column, $value, $relation, $orderBy = 'name')
  {
      return Region::with($relation)-&gt;where($column, $value)-&gt;orderBy($orderBy);
  }
  </code></pre>
  
  <p>Now the part I'm having trouble with is this part in the main code which uses my repository:</p>
  
  <pre><code>$regions = $this-&gt;regionRepository-&gt;eagerWhere('name', $term, 'country');
  
  
  if ($includeCountry) { //&lt;-- from here
      $regions-&gt;orWhereHas('country', function ($query) use ($term) {
          $query-&gt;where('name', 'LIKE', '%' . $term . '%');
      });
  }
  </code></pre>
  
  <p>How can I write that part in the repository so that ultimately I can make it look like:</p>
  
  <pre><code>$regions = $this-&gt;regionRepository-&gt;eagerWhere('name', $term, 'country');
  
  
  if ($includeCountry) {
      $regions-&gt;orWhereHas($term, 'country');
  }
  </code></pre>
  
  <p>I tried copying that part of the code to repository, but then I can't chain methods because when <code>$region</code> is fetched, it is no longer considered to be a repository instance, but <code>Eloquent</code> one. And now it is expecting <code>Eloquent</code> method instead.</p>