dongzhi5846 2017-11-06 19:55
浏览 52
已采纳

在laravel刀片中循环并显示图像,更改旧的角度代码

I'm trying to change an angular repeat that was being done on images on our website (in laravel). I'm removing angular from everything and trying to get it all done in laravel loops in the blade.

I successfully changed everything to work with our controller and the image names are being collected, but on the front end it just shows the image names not the images themselves.

Here's the original (working code) from angular:

<li ng-repeat="i in x.image_names track by $index"><a href="/imagelib/mediums/{{::i.split(',')[0] }}" target=_blank><img ng-src="/imagelib/mediums/{{::i.split(',')[0] }}" style="width: 100%; height: auto;" /></a><span class="uk-text-center" style="padding: 0 0 5px;">{{ ::i.split(',')[1] }}</span></li>

And here's my new code (showing correct image names, but only the name not the actual image):

@foreach ($pgroup->image_names as $image_name)
<li><a href="/imagelib/mediums/{{ $image_name }}" target=_blank><img ng-src="/imagelib/mediums/{{ $image_name }}" style="width: 100%; height: auto;" /></a><span class="uk-text-center" style="padding: 0 0 5px;">{{ $image_name }}</span></li>
@endforeach

Am I overlooking something in my conversion from Angular to Laravel that would cause the images to not show up?

  • 写回答

1条回答 默认 最新

  • dpauf28808 2017-11-06 20:51
    关注

    First of all, you need to replace ng-src with src in the img tag:

    <img src="/imagelib/mediums/{{ $image_name }}" />
    

    Then, since $image_name contains a CSV, you need to strip the image name. You can do this like:

    substr($image_name, 0, strpos($image_name, ','));
    

    If you want to extract the second value from $image_name, you can do it like:

    substr($image_name, strpos($image_name, ',') + 1);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败