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

Multiple Criteria in Controller method #87

Open
kskrlin opened this issue Oct 5, 2016 · 2 comments
Open

Multiple Criteria in Controller method #87

kskrlin opened this issue Oct 5, 2016 · 2 comments

Comments

@kskrlin
Copy link

kskrlin commented Oct 5, 2016

How to call more then 1 Criteria inside the controller method? For example, I want to get separated active and inactive users (status is checked between 2 tables and a few where clauses).
If I use:
$active = $this->user->getByCriteria(new GetActiveUsers($role_id))->all();
and
$inactive = $this->user->getByCriteria(new GetInactiveUsers($role_id))->all();
the second one just appends Criteria GetInactiveUsers on the above query.

How to reset query data in this example?

@coreyar
Copy link

coreyar commented Jan 24, 2017

I am also curious how this might be done. Currently trying to find a solution and will update.

@coreyar
Copy link

coreyar commented Jan 24, 2017

Here is my solution. I added a resetCriteria function to the base Repository class.

I replace Criteria with an empty Collection, apply it, then recreate the model.

...
public function resetCriteria()
    {
        $this->criteria = new Collection;
        $this->applyCriteria();
        $this->makeModel();
        return $this;
    }
...

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

No branches or pull requests

2 participants