rinvex / laravel-attributes

⚠️ [ABANDONED] Rinvex Attributable is a robust, intelligent, and integrated Entity-Attribute-Value model (EAV) implementation for Laravel Eloquent, with powerful underlying for managing entity attributes implicitly as relations with ease. It utilizes the power of Laravel Eloquent, with smooth and seamless integration.
MIT License
433 stars 104 forks source link

Using multiple where-clauses #64

Closed Brotzka closed 6 years ago

Brotzka commented 6 years ago

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 commented 6 years ago

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();