Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

BladeOfGaladrial's avatar

Problem query json fields using eloquent ORM

Here is the situation My model's got a json feild (getting stored as longtext in Mariadb 10.6.20-MariaDB-cll-lve) and I need to query and find in this feild.

Using elequoent ORM this is my query Model::whereRaw('JSON_CONTAINS(search_keywords, ?)', [45]); and calling toSql() on it returns following select * from `blogs` where JSON_CONTAINS(`search_keywords`, ?) when ->get() is called It returns empty array.

Now when I run the same command directly on my sql server which is as follows select * from blogs where JSON_CONTAINS(search_keywords, JSON_QUOTE('45'));

I get the desired output. I need to be able to query json as it is important part of a feature I am supposed to build

0 likes
2 replies
BladeOfGaladrial's avatar

@jlrdw I can understand as to why it is recommended to not use json format in the database, but in this scenario the codebase is build around this and unfortunately I cannot change this decision now. Also I in past have also used json format with new versions Laravel v11 (that could be the issue here since I am on v8) tho tricky I have made that work, but here for the life of me It just wont work.

Please or to participate in this conversation.