I have a table options and I have an array of strings ["value1", "value2", "value3"].
What I'd like to do is check if all of the values within the array are present in the table.
I've tried whereIn but I think it checks if any values exist in the table.
This is what I have done currently:
$v = ["value1", "value2", "value3"];
$options = Options::whereIn('value', $v)->get();
if ($options->count() != count($v)) {
//something must be missing
}
This works, but I wonder if there is a better way? The table has millions of records so I'd like to do only 1 query if possible.
Thanks!
Option.value1,value2andvalue3are all present in the database, as separate entries? If so, can't you just do$v = ["value1", "value2", "value3"]; $options = Options::whereIn('value', $v)->get(); if ($options->count() === count($v)) { echo "all three are present"; }. This assumes that you will only have one occurrence ofvalue1,value2andvalue3.