DEV Community

Samuel Boadu
Samuel Boadu

Posted on • Edited on

Laravel Query nested JSON Column without case sensitivity

Have you ever tried running a search in a nested JSON column inside a database with laravel where() method and it didn't work the way you expected it to due to case sensitivity(Example 1).

Example 1.
Image description

But Same query works when the case match(Example 2)

Example 2
Image description

To overcome this challenge I came up with this modification which allowed searching with whatever case return matching results(Example 3 and 4).

Example 3
Image description

Example 4
Image description

Hope this helps anyone who might face this challenge. Please Let me know if there are better ways to achieve this. Your contributions and criticism are welcome. Thank you for reading this far..... and just in case you need a package to handle the query for you in a laravel project then you can just run

composer require boadusamuel/search-nested-json-column

or read on the package at boadusamuel/search-nested-json-column

Top comments (1)

Collapse
 
michabbb_76 profile image
Michael Bladowski

that does not really look like a good choice considering the performance. wouldn't it be easier just to search in lowercase?
stackoverflow.com/a/59000485