Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AbstractRepository->getAllBy more than one 'where' #59

Open
elvendor opened this issue Jun 22, 2014 · 1 comment
Open

AbstractRepository->getAllBy more than one 'where' #59

elvendor opened this issue Jun 22, 2014 · 1 comment

Comments

@elvendor
Copy link
Contributor

I needed more than one condition in getAllBy method and I made changes like this:

public function getAllBy(array $conditions = array(), array $with = array('translations'), $all = false)
{
  $query = $this->make($with);
  if (! $all) {
    // Take only online and translated items
    $query = $query->whereHasOnlineTranslation();
  }
  if(is_array($conditions) && count($conditions))
  {
    foreach($conditions as $key => $value)
    {
      $query->where($key, $value);
    }
  }
  $models = $query->get();
  return $models;
}

And then in any Controller:

$conditions = array(
  'category_id' => $category->id,
  'type' => $type
);
$data = $this->repository->getAllBy($conditions, $relatedModels, false);

What do you think about this?

@sdebacker
Copy link
Owner

Fine, but don't forget to update interface and cache decorator + docblocks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants