Laravel 重定向图像路径
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22275365/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel redirecting image paths
提问by Panoply
My image paths are being redirected outside of public folder when using GET variables. Here is my rundown (any suggestions to improve this would be also appreciated, though not necessary:
使用 GET 变量时,我的图像路径被重定向到公共文件夹之外。这是我的纲要(任何改进这方面的建议也将不胜感激,尽管不是必需的:
Route:
路线:
Route::get('retailers/{country}', array(
'as' => 'find-retailers',
'uses' => 'SiteController@getRetailers')
);
Controller:
控制器:
public function getRetailers($country)
{
// Query Builder
$locations = DB::table('retailers_listings')
->orderBy('country', 'asc')
->where('country', $country)
->get();
return View::make('retailers.stores')
->with('retailers_listings', $locations);
}
EDIT:
编辑:
The above route and controller is what I use to handle the view stores.blade.php. Inside my views folder I have a sub directory called retailerswhich holds 2 views. index.bladeand stores.blade.
上面的路由和控制器是我用来处理视图stores.blade.php 的。在我的视图文件夹中,我有一个名为零售商的子目录,其中包含 2 个视图。index.blade和stores.blade。
/views
/retailers
index.blade.php
stores.blade.php
Image paths working in index.blade.php like so:
public/uploads/retailers/logos/image.png
像这样在 index.blade.php 中工作的图像路径:
public/uploads/retailers/logos/image.png
Image path not working in stores.blade.php like so:
/public/retailers/uploads/retailers/logos/image.png
图像路径在 stores.blade.php 中不起作用,如下所示:
/public/retailers/uploads/retailers/logos/image.png
It is loading the images from public/retailers
folder when they should be loaded from public
.
它是由加载图像public/retailers
文件夹时,他们应该被加载public
。
回答by The Alpha
If your image's path is public/uploads/retailers/logos/image.png
then use src
like this:
如果您的图像路径是public/uploads/retailers/logos/image.png
这样使用的src
:
<img src="{{ asset('uploads/retailers/logos/image.png') }}" />