search

Home  >  Q&A  >  body text

What is laravel's CROSS APPLY OPENJSON query?

I am using this query.

Convert the database structure column_name into Json format, as shown below:

[
    {
        "Date": "2022-11-14T10:45:05.424+01:00",
        "Name": "nilesh1",
        "Level": "1"
    },
    {
        "Date": "2022-11-14T10:54:15.776+01:00",
        "Name": "nilesh2",
        "Level": "2"
    }
]

I have to use the following query in Laravel eloquent:

select [customername] as [customerName]
from [opf_details] 
CROSS APPLY OPENJSON (column_name,'$') where JSON_VALUE(value,'$.Name') LIKE '%nilesh1%'

P粉898049562P粉898049562229 days ago464

reply all(1)I'll reply

  • P粉564192131

    P粉5641921312024-03-30 00:47:52

    I did this:

    myModel::whereRaw('JSON_CONTAINS(`column_name`, '\{"Name":"nilesh2"}\')')

    reply
    0
  • Cancelreply