【问题标题】:Image not displaying in view (laravel 5.2)图像未显示在视图中(laravel 5.2)
【发布时间】:2017-02-17 06:25:27
【问题描述】:

我正在使用 laravel 5.2。我正在构建一个帖子系统,用户通过单击给定的图像对其发表评论。

图像的路径已正确获取,但视图中未显示。视图中也没有给出错误。

我的控制器:

public function createemoji($action,$statusId)
{


    $path=('/images/'.$action.'.gif');





   $request=new storage();
    $request->comment=$path;
    $request->user_id=Auth::user()->id;
    $request->post_id=$statusId;
    $request->save();









     $storage=storage::where(function($query) use($statusId)
     {
         $query->where('post_id',$statusId)
            ;
    })
    ->orderBy('created_at','desc')->get();
    dd($storage);

  return redirect()->back()->with('storage',$storage);
}

我的看法:

<a href="{{route('createemoji',['action'=>'6796','statusid'=>$post->id])}}" id="6796" class="btn btn-sm"><img id="z1" src="/images/6796.gif" name="one"/></a>

我尝试显示的方式:

  @foreach($storages as $storage)
   @if($storages==$post->storage)


<div class="row">
<section class=" col-md-offset-3 col-md-5">

<h4 id="h45"></h4>
<img src="{{ $storage->comment }}">


</section>
</div>


 @endif
@endforeach

【问题讨论】:

    标签: php laravel laravel-5.2 laravel-routing


    【解决方案1】:

    尝试 img-src 的完整路径,如下所示:

    <img id="z1" src="www.yourdomain.com/images/6796.gif" name="one"/>
    

    您还可以使用浏览器检查工具检查图像元素来进行检查。例如chrome

    【讨论】:

    • 它只适用于单个图像。我想显示该帖子的所有图像。
    • 您是否检查了每张图片的$storage-&gt;comment 值。这可能是返回不正确的数据吗?
    • 如果您检查正确和不正确的图像标签,src 是什么?
    猜你喜欢
    • 1970-01-01
    • 2021-05-30
    • 2020-09-13
    • 1970-01-01
    • 2017-05-28
    • 2020-12-04
    • 2019-12-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多