DEV Community

Discussion on: Making the advanced search query with Eloquent-Builder in Laravel

Collapse
 
farrukh_uet profile image
Farrukh • Edited

Also if you want to implement a filter for a columns against multiple values.
For example following is the array you mentioned in example, but with gender filter as an array.

[
'age_more_than' => '25',
'gender' => ['male','female','custom']
'has_published_post' => 'true',
]

class GenderFilter extends Filter
{

public function apply(Builder $builder, $value): Builder
{

    if(is_array($value)){
        return $builder->whereIn('gender', $value);
    }

    return $builder->where('gender', '=', $value);
}

}

Thread Thread
 
mohammadfouladgar profile image
Fouladgar.dev

Nice.

Type of the value parameter is mixed and you can set it to any value based on your requirement.

Thanks Dear @Farrukh