Skip to content
This repository has been archived by the owner on Feb 16, 2022. It is now read-only.

Using multiple where-clauses #64

Closed
Brotzka opened this issue Jul 2, 2018 · 1 comment
Closed

Using multiple where-clauses #64

Brotzka opened this issue Jul 2, 2018 · 1 comment

Comments

@Brotzka
Copy link

Brotzka commented Jul 2, 2018

Hi!

Is it possible to user multiple where clauses on entities using attributes? Like so:

$users = App\Product::where(
    ['color','=','black'],
    ['power', '>','200'],
    ['max_speed','>','260']
)->get();

Thanks in advance!

@IsraelOrtuno
Copy link
Contributor

Yes it is, but you cannot use the where directive like that, it's a caveat. As mentioned in the docs (https://github.com/rinvex/attributes#querying-models), you should use the whereHas method. Every attribute acts as a relationship, so they can be queried that way:

$companies = Company::whereHas('Cities', function (\Illuminate\Database\Eloquent\Builder $builder) {
    $builder->where('content', 'Alexandria');
})->get();

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

No branches or pull requests

2 participants