图片未在Laravel 4 Framework中显示

钢铁之心j18

它显示图像的索引index.blade.php http://imgur.com/hZshMrl很好,当我单击{{link_to_action(PostController @ show','Read Blog'}}}的下一页时,它拒绝显示图像。我签入元素检查img文件以打开src =“ img / 1.img',没有可用的图像。当我返回index.blade.php时,它恢复正常,这是为什么呢?

<div class="container">

@forelse($posts as $post)
    <div class="blogs">
        <h3>{{{ $post->title }}}</h3>
        <p class="info"> {{{ $post->content }}} </p>
        <p class="info"> by: {{{ $post->user->first_name }}} {{{ $post->user->last_name }}} </p>
        {{link_to_action('PostController@show','Read Blog', array($post->id))}}
        <span class="posted" style="text-align:left">{{{ $post->created_at->format(Post::DATE_FORMAT)}}}</span>
    @if ($post->img_path)
        <p style="text-align:right"><img class="img-upload" src="{{ $post->img_path }}" style="max-width: 25%">
    @endif
    </div>
@empty
      <p>No Blogs</p>
@endforelse
{{ $posts->links() }}

</div>

show.blade.php http://imgur.com/WdtkyAt

    <div class="container">


    @if ($post->img_path)
        <img class="img-upload" src="{{ $post->img_path }}" style="max-width: 25%">
    @endif

    </div>

Postcontroller.php

public function show($number)
{
    //
    $post = Post::find($number);


    return View::make('posts.show')->with('post', $post);
}

Mysql工作台为“帖子”表。

我已经尝试过那些{{{$ post-> user-> img_path}}} {{$ post-> img_path}} {{$ post-> user-> img_path}} {{$ post-> img_path}}

其失败显示了图像。

马丁·比恩(Martin Bean)

我想这是因为存储在数据库中的图像文件名引用是相对的。您需要输入完整路径,因为如果转到http://example.com/posts/1,则模板将在名为posts的目录中查找img / filename.jpg,而不会存在。

相反,您应该使用绝对URL。如果您的图像只是存储在public / img中,则可以在show.blade.php模板中执行以下操作:

@if ($post->img_path)
    <img class="img-upload" src="{{ asset($post->img_path) }}" style="max-width: 25%">
@endif

这会将网站的根URL放在图像的路径之前。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

图片未在Laravel 4 Framework中显示

来自分类Dev

图片未在imageview中显示

来自分类Dev

图片未在imageview中显示

来自分类Dev

图片未在div中显示

来自分类Dev

图片未在现场显示

来自分类Dev

Laravel 5 中的 CKEditor 4 未在工具栏中显示 iFrame 图标

来自分类Dev

外部图片未在Android中显示

来自分类Dev

Cron作业未在Google App Engine + Laravel 4中执行

来自分类Dev

图片未在AsciiDoc中呈现

来自分类Dev

CSS网址中的图片未在GatsbyJS中显示

来自分类Dev

CSS背景图片未在Heroku中显示

来自分类Dev

该图片未在SearchBox中显示结果建议

来自分类Dev

Reddit API预览图片未在ReactJs中显示

来自分类Dev

上传的头像图片未在GitLab中显示

来自分类Dev

UIView 未在 ViewController Swift 4 中显示元素

来自分类Dev

资产图片未在发布模式下显示

来自分类Dev

图片未在Silveright控件上显示

来自分类Dev

在laravel4中显示图像的问题

来自分类Dev

API验证错误未在Laravel中显示

来自分类Dev

聚合查询未在 laravel 中显示输出

来自分类Dev

Laravel 4:会话刷新消息未在页面刷新中消失

来自分类Dev

自定义验证类未在Laravel 4中加载

来自分类Dev

图片未在我的 DIV 中对齐

来自分类Dev

图片未显示,无法在Laravel中更新我的图片

来自分类Dev

某些图片未在移动浏览器中显示(但在桌面浏览器中显示)

来自分类Dev

Laravel 4-更改(上传图片名)

来自分类Dev

CSS背景图片未在移动设备上显示

来自分类Dev

网站上的图片未在iOS设备上显示

来自分类Dev

Django上传的图片未在生产中显示