laravel/framework · error · RuntimeException

This database engine does not support case sensitive like op

Error message

This database engine does not support case sensitive like operations.

What it means

The base Grammar::whereLike() throws when $where['caseSensitive'] is true. Only SQLite, MySQL, and Postgres override whereLike to handle case-sensitive matching natively. SQL Server uses the base Grammar, so requesting a case-sensitive LIKE on SQL Server throws, because SQL Server's collation already determines case sensitivity and there is no portable keyword Laravel can emit.

Source

Thrown at src/Illuminate/Database/Query/Grammars/Grammar.php:338

     */
    protected function whereBitwise(Builder $query, $where)
    {
        return $this->whereBasic($query, $where);
    }

    /**
     * Compile a "where like" clause.
     *
     * @param  \Illuminate\Database\Query\Builder  $query
     * @param  array  $where
     * @return string
     *
     * @throws \RuntimeException
     */
    protected function whereLike(Builder $query, $where)
    {
        if ($where['caseSensitive']) {
            throw new RuntimeException('This database engine does not support case sensitive like operations.');
        }

        $where['operator'] = $where['not'] ? 'not like' : 'like';

        return $this->whereBasic($query, $where);
    }

    /**
     * Compile a "where null safe equals" clause.
     *
     * @param  \Illuminate\Database\Query\Builder  $query
     * @param  array  $where
     * @return string
     */
    protected function whereNullSafeEquals(Builder $query, $where)
    {
        return $this->wrap($where['column']).' is not distinct from '.$this->parameter($where['value']);
    }

View on GitHub (pinned to bd6b5437e6)

Solutions

  1. On SQL Server, drop the caseSensitive flag (pass false) and rely on the column collation to control case sensitivity.
  2. If you need guaranteed case sensitivity on SQL Server, alter the column collation to a CS (case-sensitive) collation instead of using the builder flag.
  3. Guard the call: only pass caseSensitive=true on engines whose driver is mysql, sqlite, or pgsql.

Example fix

// before
$query->whereLike('name', $term, true);

// after (SQL Server friendly)
$driver = $query->getConnection()->getDriverName();
$query->whereLike('name', $term, in_array($driver, ['mysql','sqlite','pgsql']));
Defensive patterns

Strategy: validation

Validate before calling

$driver = $query->getConnection()->getDriverName();
$caseSensitive = in_array($driver, ['mysql','sqlite','pgsql']) ? $requestedCaseSensitive : false;
$query->whereLike('name', $term, $caseSensitive);

Type guard

function supportsCaseSensitiveLike(\Illuminate\Database\Connection $connection): bool
{
    return $connection instanceof \Illuminate\Database\MySqlConnection
        || $connection instanceof \Illuminate\Database\SQLiteConnection
        || $connection instanceof \Illuminate\Database\PostgresConnection;
}

Prevention

When it happens

Trigger: Calling whereLike($column, $value, true) (third arg caseSensitive=true), orWhereLike(..., true), whereNotLike(..., true), or whereNotLike with case sensitivity on a sqlsrv connection.

Common situations: Building search filters with whereLike(..., caseSensitive: true) in a package intended to be engine-agnostic, then running against SQL Server. Migrating a MySQL app to SQL Server where the case-sensitive flag was previously honoured.

Related errors


AI-assisted analysis of laravel/framework@bd6b5437e6 (2026-08-06). Data as JSON: /data/errors/ce4dc6b2a711a9e6.json. Report an issue: GitHub.