从 Laravel 中的应用程序目录加载图像
Load an image from an app directory in Laravel
在我的 app/
目录中,我创建子目录调用 Files/
我把我所有的博客 img 都存储在那里,现在我试图在我的 blade 中显示,但我做不到。有可能吗?
我试过了
我的图片路径示例
/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>
结果,
控制台错误
任何建议/提示将不胜感激。
要在浏览器中加载图像,该图像需要位于 webroot 目录中。对于 Laravel,默认情况下这是 public/
目录。
因此您需要将 Files
文件夹移动到 public/
中。那么你可以简单地:
<img src="/Files/...
您可能还会发现 asset()
方法有帮助:
<img src="{{ asset('Files/...') }}...
在我的 app/
目录中,我创建子目录调用 Files/
我把我所有的博客 img 都存储在那里,现在我试图在我的 blade 中显示,但我做不到。有可能吗?
我试过了
我的图片路径示例
/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>
结果,
控制台错误
任何建议/提示将不胜感激。
要在浏览器中加载图像,该图像需要位于 webroot 目录中。对于 Laravel,默认情况下这是 public/
目录。
因此您需要将 Files
文件夹移动到 public/
中。那么你可以简单地:
<img src="/Files/...
您可能还会发现 asset()
方法有帮助:
<img src="{{ asset('Files/...') }}...