Jemy
Jemy

Reputation: 139

How to Show Images from Storage Path using Livewire in Laravel 7

enter image description hereI am new in using Livewire for my cart in my e-commerce Laravel 7 project. I want to show the product image of each item in the cart. I have @foreach ($cartItems as $item) on my table data. When I try this code

<img src="{{asset('storage/'.$item->cover_img)}}">

to try to show the images saved to my storage path, I get an error like the image above. But when I try:

<img src="{{asset('storage/'.$item['cover_img'])}}">

I'm getting an ErrorException Undefined index: cover_img. All the other $item is working and getting the needed data except the image. On my other blades without livewire <img src="{{asset('storage/'.$item->cover_img)}}> works fine.

How do I do this properly in livewire? Any advice would be appreciated. Thanks in advance!

When I do a {{dd($item)}}, this is what I get:

enter image description here

Upvotes: 4

Views: 4907

Answers (1)

Jemy
Jemy

Reputation: 139

This solved my problem:

<img src="{{ asset('storage/'.$item['associatedModel']['cover_img']) }} " />

Thanks!

Upvotes: 3

Related Questions