[英]How can I change the path of images/files inside different views?
This is working fine to show all the images inside the public folder of my home.blade view at www.mygallery.com 可以很好地显示www.mygallery.com上我的home.blade视图的公用文件夹内的所有图像。
@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. 但是,当我尝试按类别(www.mygallery.com/tags/cats)过滤结果时,$ item-> image试图到达tag / images / myimage.jpg中的每幅图像,这当然是不存在的。
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. 问题是我不想创建public / tags / images文件夹,所以我想知道无论调用哪个视图/路由,如何显式指向正确的文件夹(public / images)。
The problem here is that $item->image
is a relative path. 这里的问题是$item->image
是相对路径。 So depending on your current URL you will link to different paths. 因此,根据您当前的URL,您将链接到不同的路径。
To generate an absolute URL, use the asset()
function: 要生成绝对 URL,请使用asset()
函数:
<a href="{{$item->url}}"><img src="{{ asset($item->image) }}" alt="{{$item->title}}"></a>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.