title: Where to place Laravel queries using Repository pattern
body: <p>I am currently creating an API using <a href="https://lumen.laravel.com/" rel="nofollow noreferrer">lumen</a> and I'm not entirely confident about where I should be putting my database queries. I am using the Repository pattern and currently my layout is like so:</p>
  
  <ol>
  <li>Controller loads Custom Repository</li>
  <li>Repository method contains eloquent query and returns result.</li>
  </ol>
  
  <p><code>Controller --&gt; Custom Repository --&gt; Model</code></p>
  
  <p><code>Controller &lt;-- Custom Repository &lt;-- Model</code></p>
  
  <p>--
  A high level code example of how I am currently doing it:</p>
  
  <p>Controller.php</p>
  
  <pre><code>public function browse()
  {
      // customRepo added via dependency injection
      $this-&gt;customRepo-&gt;browse()
  }
  </code></pre>
  
  <p>customRepo.php</p>
  
  <pre><code>public function browse()
  {
      // other logic here
      return Member::where('active', 1)-&gt;orderBy('date', 'desc')-&gt;get()
  }
  </code></pre>
  
  <p>I am using Eloquent to make queries to the database and am currently all of these calls are happening inside the Repository which feels a bit odd to me because my Repositories are filling up with Eloquent (and some query builder) queries however I have seen from a few sources that it's <a href="https://laracasts.com/discuss/channels/laravel/where-to-place-the-queries/replies/107044" rel="nofollow noreferrer">not correct</a> to put the queries inside the model.</p>
  
  <p>I feel like my current approach is probably correct I just wanted to see if anyone could definitively tell me which is best - it doesn't make a whole lot of sense for me to pad out the models with custom methods if not needed.</p>