Table Filter for Repeater Json Column

Hi guys. I am having problems with the data saved by a repeater. As the documentation says, I created a json column for the repeater and casted it to array in the model. Now I'm trying to create a filter on that column, but the where and whereJsonContains Eloquent methods don't seem to work. I've also tried with raw SQL but it doesn't find any record. Here's the content of the column:
"[
{
\"visibility_type\":\"Section Home Page\",
\"visibility_time\":27,
\"visibility_price\":233.84
},
{
\"visibility_type\":\"Newsletter\",
\"visibility_time\":21,
\"visibility_price\":200.3
}
]"
"[
{
\"visibility_type\":\"Section Home Page\",
\"visibility_time\":27,
\"visibility_price\":233.84
},
{
\"visibility_type\":\"Newsletter\",
\"visibility_time\":21,
\"visibility_price\":200.3
}
]"
Am I doing something wrong? Thank you very much for your help and sorry for the stupid question. In the images: my repeater code and the filter.
No description
No description
Solution:
The error was caused by my test data: by using json_encode in the factory code, together with casting, the json was saved with the "". Maybe it can be useful in the future for someone with a problem similar to mine 🥲...
Jump to solution
3 Replies
Davide Cariola
I've understood that the problem is that the JSON is saved as a string. In fact, I've delete the "" manually in the db and the query works. But how to do it in the code? 😅
Davide Cariola
The query in the image works, but only for the record where I deleted the "" around the JSON
No description
Solution
Davide Cariola
The error was caused by my test data: by using json_encode in the factory code, together with casting, the json was saved with the "". Maybe it can be useful in the future for someone with a problem similar to mine 🥲