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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 09:09:16  来源:igfitidea点击:

Laravel redirecting image paths

phplaravel

提问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.bladestores.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/retailersfolder when they should be loaded from public.

它是由加载图像public/retailers文件夹时,他们应该被加载public

回答by The Alpha

If your image's path is public/uploads/retailers/logos/image.pngthen use srclike this:

如果您的图像路径是public/uploads/retailers/logos/image.png这样使用的src

<img src="{{ asset('uploads/retailers/logos/image.png') }}" />