简体   繁体   中英

Equal or greater than with whereIn or array in laravel

I have this array:

array:3 [▼
    0 => "5"
    1 => "10"
    2 => "20"
]

This is values of discounts I need to brings the products that has Equal or greater than the value in array:

Product::whereHas('discounts',function($q) use($value){
        $q->where('type','percentage')->whereIn('value','>=',$value);
 });

$value is the above array

So, I need to bring the products that has discount 5% or more | and also bring the products that has 10% or more | same thing with 20

Just find the min and get all discounts greater then that:

Product::whereHas('discounts',function($q) use($value){
    $q->where('type','percentage')
      ->where('value','>=',min($value));
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM