Is this data coming from an Eloquent Model? If so, you can cast the day_x attributes to array/json easily.
Nov 3, 2022
2
Level 1
API Resource where column is array or encoded json
I have a database structure that contains columns where the data is stored as an array. How do I create an API Resource that helps me consume the data from the array and also use the array elements as key to query another table.
The below json is a workout data where day_1 to day_7 contains data which is an array of the index of exercises on another table.
Please if there's any suggestion on how to work with this when one needs to query the individual exercises whoe key are in the array for their respective days.
Thanks
{
{
"data": [
{
"id": 2,
"title": "consequatur",
"description": "Doloremque ratione asperiores natus. Non cum amet impedit quod vel voluptate mollitia. Culpa sed omnis alias est. Libero architecto quae numquam est consequatur ea vero.",
"goal": "body building",
"level": "intermediate",
"duration": 45,
"day_1": "[1,2,3,4,5,6,7,8,9]",
"day_2": "[4,5,2,6,1,3]",
"day_3": "[2,4,6,8,1,5,7,3]",
"day_4": "[1,2,3,4,5,6,7,8,9]",
"day_5": "[1,2,3,4,5,6,7,8,9]",
"day_6": "[2,4,6,8,1,5,7,3]",
"day_7": "[4,5,2,6,1,3]",
"price": 2644.71999999999979991116560995578765869140625,
"image": "https://via.placeholder.com/640x480.png/00aaff?text=ex"
}
}
Please or to participate in this conversation.