A
A
Alexey Nikolaev2018-11-07 11:53:13
PostgreSQL
Alexey Nikolaev, 2018-11-07 11:53:13

Is it possible to register a new operator for Query Builder in Laravel?

Good day.
I use Laravel + PostgreSQL, and it became necessary to make a case-insensitive comparison of column values ​​with any of the array values. The ILIKE ANY binding is great for this, but Laravel does not treat it as an operator.

$query->where('data', 'ilike', $keywords); // <--- все супер

// думает, что ilike any - это значение и начинает сравнивать с ним
$query->where('data', 'ilike any', $keywords); // <--- $keywords игнорируются

Can I register my own operator for Query Builder? I really don't want to use whereRaw or loop through $keywords.
Thanks in advance.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Victor, 2018-11-08
@v_decadence

What is the problem with using whereRaw? There you can use ?-bindings and not be afraid of injections.
You can try like this
Registration of their operators is not provided, as far as I know.

A
Alex Wells, 2018-11-08
@Alex_Wells

Can. Use mixins: *poke*
After that, write in the @method vendor in the dockblock. Yes, the solution is very far from ideal, but we have what we have :/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question