Where_in() function

in the old GC community edition I was able to add the (missing) where_in() function

Is there a way to do the same on GC Ent?

I also tried with $crud->where([“mydbfield IN ?” => “(1,2,3,4)”]);
but the where() function will add some " AND " string

is there a way to add back again the “where_in()” function?

thanks

Hello @Phil ,

You can always use the where method but as a string. So for example let’s say that you would like to have the following where in:

WHERE country IN('US','GR')

you can do that by using the string element of where but you will need to make sure that you start and finish with a parenthesis. For example:

$countries = ['US', 'GR'];
if (!empty($countries)) {
    // Don't forget to add a parenthesis to the string 
    // or else the filtering and quick search will not work
    $crud->where("(country IN('" . implode("','", $countries) ."'))");
}

and of course you can create your own helper for that, for example something like this:

function groceryCrudWhereIn($fieldName, $in = array()) {
    if (empty($in)) {
        // we have to return something valid for where.
        // If your array is empty and you would like to have 
        // the opposite behavior you can change this
        // to (1 = 0)
        return '(1 = 1)';
    }

    return "(`$fieldName` IN('" . implode("','",  $in) ."'))";
}

// Example of usage:
$countries = ['US', 'GR'];
$crud->where(groceryCrudWhereIn('country' , $countries));
1 Like

Thanks! I’ll try that!