I have some data i have stored in mysql and it looks like this
["1109255736625955df9fbef.jpg","707361535625955dfa0564.jpg","1126563303625955dfa0c5c.jpg"]
i stored this data as an array in a field called product_images that holds strings.
Is there a way of iterating through this data without making it a php array at first but instead iterate it in blade straight from the database?.
This doesn’t work
<div class="row">
@foreach ($product->product_images as $image)
<div class="col-3">
{{$image}}
</div>
@endforeach
</div>
>Solution :
you should use mutators to cast array
Product in model add:
protected $casts = [
'product_images' => 'array',
];
The cast from string to array is done under the hood for you