Laravel9 with Postgis whereRaw() question mark is not supposed to be parameter

30 views Asked by At

I need to use whereRaw query which looks like this

return $query->whereHas('translations', function(Builder $q) use ($value) {
    $q->whereRaw("unaccent(title) ILIKE unaccent('%?%')", [$value]);
});

This builder throws me this error: bind message supplies 1 parameters, but prepared statement "pdo_stmt_00000003" requires 0

So I dont know what should I do. The expresion in unaccent() function has to be enclosed by single quotes otherwise it does not work at all. But then the question mark is not supposed to be a query parameter.

Does somebody know how to solve this issue?

EDIT: I found out that this work but I really dont like it.

return $query->whereHas('translations', function(Builder $q) use ($value) {
    $q->whereRaw("unaccent(title) ILIKE unaccent('%'||?||'%')", [$value]);
});
0

There are 0 answers