I am currently creating an API using lumen 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:
- Controller loads Custom Repository
- Repository method contains eloquent query and returns result.
Controller --> Custom Repository --> Model
Controller <-- Custom Repository <-- Model
-- A high level code example of how I am currently doing it:
Controller.php
public function browse()
{
// customRepo added via dependency injection
$this->customRepo->browse()
}
customRepo.php
public function browse()
{
// other logic here
return Member::where('active', 1)->orderBy('date', 'desc')->get()
}
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 not correct to put the queries inside the model.
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.