Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Reading a raw array stored in mysql with blade

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?.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading