Skip to content
Advertisement

Multiple image retrieval with laravel

I have uploaded multiple images to database already. Now i am trying to display them in my view. while using foreach to loop through images i am getting error – Invalid argument supplied for foreach()

This is my blade

JavaScript

This is my store of controller

JavaScript

This is how i have defined coverage table

JavaScript

on dumping $coverage->gallery in store controller i receive this:

“[“70187225_683426155503359_4595847093867773952_n.jpg”,”70744555_683429382169703_8264311195482193920_n.jpg”]”

In database the same is saved as BLOB

Advertisement

Answer

Because $coverage->gallery is not an Array. Edit: I saw that your gallery column is type binary. I don’t know if it is possible to save a json_encoded String to binary column.

I would also reccommend you to use another table for gallery items with relationship to your coverage entries. Take a look at Eloquent Relationships

If you want to keep your current (and dirty) procedure:

If you store it with json_econde() you’ll have to decode it first if you want to loop over it.

Try changing gallery column to string and then do @foreach(json_decode($cove->gallery, true) as $image)

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement