Laravel Eloquent case insensitive like search in MySql json columns
Nov 20, 2019Recently while working on one of my office projects, I stumbled upon a issue
where I was receiving zero results for the like search on orders
table while using Laravel's Eloquent
. To explain it better, I
was performing the following query
There is nothing wrong about the query I have formed here, except that I was using MySQL json columns instead of default ones. So, by enabling the laravel debugbar package, I found that query formed by Laravel is as follows
select * from `orders` where json_unquote(json_extract(`user`, '$."name"')) LIKE '%Sarav%'
The problem with the above query is, MySQL json like search is
I have shown two approaches to resolve this issue and you can follow which ever you feel like you are comfortable with.
Happy Coding!