For example I need to find a user which its status
is 0 and its name is John
. So beside usual methods for a Repository pattern (e.g. find
, create
), I decide to create a method in UsersRepository
called findJohnWithStatusZero
or to be more generic, a method called findUserWithStatusAndName
UsersRepository.php
<?php
class UsersRepository
{
public function create(array $data)
{
//
}
public function find($id)
{
//
}
public function findUserWithStatusAndName($status, $name)
{
return User::where('status', $status) -> where('name', $name) -> first();
}
}
Controller.php:
...
public function index(UsersRepository $users)
{
$john_zero = $users -> findUserWithStatusAndName(0, 'john');
}
...
I want to know, if I use these customized methods in my Repository, do I violate the Repository Pattern principles?
Edit: I provided more generic method name instead of findJohnWithStatusZero
findJohnWithStatusZero
is a bit strange. It is an example. The more realistic names could befindByType
,findByRegisterDate
,deleteOldPosts
– AliN11 Oct 24 '18 at 18:56