1

I'm using JSONb columns of the PostgreSQL.

I have such an array in my data column

{
    myKey: []
}

How can I check through Laravel, if this array is empty or not?

Something like

MyModel::where('data->myKey'...)
1

1 Answer 1

1

You have to use a raw statement:

MyModel::whereRaw("json_array_length((data->'myKey')::json) > 0")

In Laravel 5.7.2 you can use whereJsonLength():

MyModel::whereJsonLength('data->myKey', '>', 0)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.