I am passing an object to a view so that I can randomly pick images for a slider. That is fine and a dump shows the class being passed and so on. So I want to have a line in the loop that makes it an asset but it does not work:
@foreach ($slider1 as $item)
<div class="item">
<img src="{{asset('/uploads/$item->image') }}" alt="" />
</div>
@endforeach
UPDATE
You were putting the variable $item->image
inside single quote(')
. Therefore it was treated as constant string. To get the value of the variable you must use the string concatenation approach so the value is retrieved first and then append it the url/path.
@foreach ($slider1 as $item)
<div class="item">
<img src="{{asset('/uploads/'.$item->image) }}" alt="" />
</div>
@endforeach