Home > Software engineering >  Laravel eloquent limit of the array size passed into whereIn
Laravel eloquent limit of the array size passed into whereIn

Time:01-29

Is there a limit to the number of elements and/or their length in the array passed into the WHEREIN eloquent method? For example:

$skuChunks = array_chunk($skus, 20);
foreach ($skuChunks as $chunk) {
    BCProduct::whereIn('sku', $chunk)->update(['flag' => $flagValue]);
}

What is the biggest number that I can use instead of 20? If the length of the SKU is 10 symbols, would that affect the number of elements ($chunk size) in comparison if the length was 5 symbols?

Thanks

CodePudding user response:

you can slice array when send in whereIn with this method

array_slice($array, 0, 5) // return the first five elements

CodePudding user response:

$skuChunks = array_chunk($skus, 20);
foreach ($skuChunks as $chunk) {
    BCProduct::whereIn('sku', $chunk)->update(['flag' => $flagValue]);
}

I think you have to make a condition to be sure that sku is not too much, so a condition that checks if sku is not greater than 20

  •  Tags:  
  • Related