I had run in an case where I need some help, I have a web application where admin can create forms from the dashboard, each form has fields and properties where fields consists of
image, name, type, required, public
and properties consists of only name
So I created the tables as below:
forms_table:
ID | Name | status
forms_fields_table
ID | form_id | name | slug | type | options | required
forms_properties
ID | form_id | name | slug
And on the other side other users can create a real-estate where they will have to fill the data of the real-estate category selected form, So i save filled form data in a column in real-estate table
the data saved like this
[
{slug_value}: {
"name": "xxxx",
"value": "xxxx",
"slug": "ssss",
"value": 42
},
{slug_value}: {
"name": "yyy",
"value": "yyy",
"slug": "aaaa",
"value": 42
},
]
where all these data are dynamic and the key of each json is the same as slug, and the user should be able to filter the real-estates by these dynamic data by slug and value.
So the question comes here, I know that I can filter data by nested JSON like this : DB::table('realestates')->where('attributes->{slug_name}->value', 'red')->get();
but I didn't find a way to index dynamic nested JSON so it will take some time in filtering process.
And as I was thinking, it came to my mind what if I store these dynamic data as string and filter the string like this attributes = "value":"search_query"
but I don't want to change the structure for nothing.
I'm using laravel