Laravel Eloquent Ignore Casing

Use whereRaw with parameter binding to sanitize your whereRaw statement:

$term = strtolower($vars['language']);
Item::whereRaw('lower(language) like (?)',["%{$term}%"])->get();

Prev answer In some dabases you can use operator ilike in your where. For example

Item::where('language', 'ilike', $vars['language'])->get();

All available operators are:

protected $operators = array(
    '=', '<', '>', '<=', '>=', '<>', '!=',
    'like', 'not like', 'between', 'ilike',
    '&', '|', '^', '<<', '>>',
);

Edit: ilike is case-insensitive like.


As per this post, a db-independent way to solve this would be:

Item::whereRaw('LOWER(language) = ?', [$vars['language']])->get();