Search code examples
laravelmysql-8.0

JSON_CONTAINS doesn't recognize my column mysql v.8.0.17 laravel 5.6


I have to do a query similar to this:

SomeModel::whereRaw("JSON_CONTAINS(column, '', '$.a')")->get();

column contains JSON *{"a":null}*;

With mysql version 5.7 everything works fine, i get empty collection but on a database on digitalocean which is mysql v8.0.17 i get this error:

Illuminate/Database/QueryException with message 'SQLSTATE[22032]: <>: 3141 Invalid JSON text in argument 1 to function json_contains: "The document is empty." at position 0. (SQL: select * from 'table' where JSON_CONTAINS(column, '', '$.a'))'

I'm stuck on this for days, please help! :)


Solution

  • The problem is empty string that you are passing as argument.

    Try:

    SomeModel::whereRaw("JSON_CONTAINS(column, null, '$.a')")->get();