This is working fine to show all the images inside the public folder of my home.blade view at www.mygallery.com
@foreach($items as $item)
<div class="box">
<div class="boxInner">
<a href="{{$item->url}}"><img src="{{$item->image}}" alt="{{$item->title}}"></a>
</div>
</div>
@endforeach
By the way this is how my routes file looks like.
Route::get('', array('as'=>'itemshome', 'uses'=>'ItemsController@show_items'));
Route::resource('upload', 'ItemsController');
Route::get('tags/{category?}', array('as'=>'itemstag', 'uses'=>'ItemsController@show_items'));
But when I try to filter results by category (www.mygallery.com/tags/cats) $item->image is trying to reach every image at tags/images/myimage.jpg which of course doesn't exist.
The thing is that I don't want to create a public/tags/images folder, so I wonder how can I explicitly point to the correct folder (public/images) no matter what view/route is making the call.
The problem here is that $item->image
is a relative path. So depending on your current URL you will link to different paths.
To generate an absolute URL, use the asset()
function:
<a href="{{$item->url}}"><img src="{{ asset($item->image) }}" alt="{{$item->title}}"></a>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.