从Laravel中的app目录加载图像

时间:2015-08-31 19:56:43

标签: php image laravel laravel-5 blade

在我的app/目录中,我创建子目录调用Files/

我将我所有的博客存储在那里,现在我试图在我的刀片中显示,但我不能。它甚至可能吗?

我试过

我的图片路径示例

/app/Files/blogs/Test/img/Screen%20Shot%202015-08-31%20at%201.35.22%20PM.png

img标记

<img src="{{app_path()}}/Files/blogs/{{$blog->name}}/img/{{$blog->img_path}}">

代码块

<ul class="portfolioContainer grid row no_left_right isotope">

        <?php

        use App\Blog;
        $blogs = Blog::all();

        ?>


        @foreach( $blogs as $blog)

        <li class="col-xs-12 col-sm-4 col-md-4 col-lg-4 isotope-item">
            <div class="lightCon">
              <figure>
                <div class="img_hover">
                <img src="{{app_path()}}/Files/blogs/{{$blog->name}}/img/{{$blog->img_path}}">

                </div>
                <figcaption>
                  <h4><a href="#">{!! $blog->name !!}</a></h4>
                  <div class="metaInfo"> <span>By <a href="#" class="admin"></a> </span> {{ $blog->user->username }}</span></div>
                  <p>{!! $blog->description !!}</p>
                </figcaption>
              </figure>
            </div>
          </li>

        @endforeach

      </ul>

结果,

enter image description here

控制台错误 enter image description here

任何建议/提示将不胜感激。

1 个答案:

答案 0 :(得分:3)

要在浏览器中加载图像,该图像需要位于webroot目录中。对于Laravel,默认情况下这是public/目录。

因此,您需要移动Files文件夹并将其放在public/内。那么你可以简单地说:

<img src="/Files/...

您可能还会发现asset()方法很有用:

<img src="{{ asset('Files/...') }}...