php - laravel eloquent - check if all values of array in table

Solution:

The answer in the comments by justcarty is technically correct, but you can reduce the load by not pulling in the options if you don't intend to use them.

if (Option::whereIn('value', [...])->count() != count([...])) {
    //perform action
}

Also note, as justcarty mentioned, this won't work if you have multiple occurrences of a value in your database, but you can get around this by adding DISTINCT clause to your query.

if (Option::distinct(['value'])->whereIn('value', [...])->count() != count([...])) {
    //perform action
}

Answer

Solution:

whereIn check specifically for that one value in the arrays.

You can try this:

$search_values = ['value1', 'value2', 'value3'];
$found = true;
foreach ($search_values as $search) {
    if (!Search::where('column', $search)->first()) {
        $found = false;
    }
}

if (!$found) {
    // Something must be missing
}

Source