The database table looks like this:
The "extras" column in the database is storing an array of objects that look like this:
[
{"id":92,"product_id":8966,"extra_type":"Extras","extra_name":"Olives"},
{"id":93,"product_id":8966,"extra_type":"Extras","extra_name":"Ketchup"},
{"id":92,"product_id":8966,"extra_type":"Extras","extra_name":"Olives"}
]
The code below (from the Laravel blade) returns the array of objects.
@foreach($item->orderedProducts as $op)
<tr>
<td>
<span>{{ $op['extras'] }}</span><br>
</td>
</tr>
@endforeach
$op returns this:
{
"id": 171,
"product_id": 8966,
"order_id": 175,
"price": 11,
"count": 1,
"product_data": "{\"id\":8966,\"name\":\"Camera Br\\u00fbl\\u00e9e\",\"description\":\"Lorem ipsum dolor sit amet consectetur adipiscing elit etiam, conubia tempus sed dapibus augue gravida accumsan. Odio congue in blandit iaculis risus gravida parturient dictum quis rhoncus volutpat ornare tincidunt, dignissim ut pellentesque.\",\"price\":11,\"price_old\":null,\"category_id\":4584,\"created_at\":\"2019-03-17 14:59:56\",\"updated_at\":\"2019-04-17 16:37:03\",\"tax_group_id\":null,\"sort\":1,\"vendor_id\":null,\"option1\":null,\"option2\":null,\"option3\":null,\"option4\":null,\"option5\":null,\"option6\":null,\"images\":[\"http:\\/\\/localhost:8000\\/product_images\\/ElI9GImttc.jpg\"],\"formatted_price\":\"\\u00a311\",\"formatted_old_price\":\"0\",\"tax_value\":0,\"city_id\":null,\"restaurant_id\":null,\"product_images\":[{\"id\":9000,\"image\":\"\\/product_images\\/ElI9GImttc.jpg\",\"product_id\":8966,\"created_at\":\"2019-04-08 15:16:53\",\"updated_at\":\"2019-04-08 15:16:53\"}],\"tax_group\":null,\"category\":{\"id\":4584,\"name\":\"Random Things\",\"_lft\":1,\"_rgt\":2,\"parent_id\":null,\"created_at\":\"2018-11-09 13:15:01\",\"updated_at\":\"2019-04-17 16:47:21\",\"restaurant_id\":null,\"city_id\":null,\"category_image\":null,\"has_children\":0,\"image_url\":\"http:\\/\\/localhost:8000\\/category_images\\/a64be5a696402b0fe3649536ab6a49e4_1555519641.jpg\"},\"added\":true}",
"extras": "[{\"id\":93,\"product_id\":8966,\"extra_type\":\"Extras\",\"extra_name\":\"Ketchup\",\"extra_price\":\"1.20\",\"extra_added\":true,\"price_sum\":1.2,\"extra_count\":1}]",
"exclusions": "[{\"id\":117,\"product_id\":8966,\"extra_type\":\"Exclusions\",\"extra_name\":\"Rat poison\",\"extra_price\":null,\"exclusion_added\":true}]",
"created_at": "2019-04-27 10:35:11",
"updated_at": "2019-04-27 10:35:11",
"product": {
"id": 8966,
"name": "Camera Brûlée",
"description": "Lorem ipsum dolor sit amet consectetur adipiscing elit etiam, conubia tempus sed dapibus augue gravida accumsan. Odio congue in blandit iaculis risus gravida parturient dictum quis rhoncus volutpat ornare tincidunt, dignissim ut pellentesque.",
"price": 11,
"price_old": null,
"category_id": 4584,
"created_at": "2019-03-17 14:59:56",
"updated_at": "2019-04-17 16:37:03",
"tax_group_id": null,
"sort": 1,
"vendor_id": null,
"option1": null,
"option2": null,
"option3": null,
"option4": null,
"option5": null,
"option6": null,
"images": [
"http://localhost:8000/product_images/ElI9GImttc.jpg"
],
"formatted_price": "£11",
"formatted_old_price": "0",
"tax_value": 0,
"city_id": null,
"restaurant_id": null,
"product_images": [
{
"id": 9000,
"image": "/product_images/ElI9GImttc.jpg",
"product_id": 8966,
"created_at": "2019-04-08 15:16:53",
"updated_at": "2019-04-08 15:16:53"
}
],
"tax_group": null,
"category": {
"id": 4584,
"name": "Random Things",
"_lft": 1,
"_rgt": 2,
"parent_id": null,
"created_at": "2018-11-09 13:15:01",
"updated_at": "2019-04-17 16:47:21",
"restaurant_id": null,
"city_id": null,
"category_image": null,
"has_children": 0,
"image_url": "http://localhost:8000/category_images/a64be5a696402b0fe3649536ab6a49e4_1555519641.jpg"
}
}
}
What I am trying to achieve is obtain all the values of (for example) "extra_name" from "extras:".
The desired output should be something like:
Olives Ketchup Olives

{{ $op->extras }}?{{ $op->extra_type }}, I guess.