如何在 Laravel 5.7 中使用循环在滑块中显示单个图像?
我试图在滑块中显示单个图像,但每当用户单击此图像时,它就会在我运行滑块的 data-src="multiple-images-here"
中打开一个弹出窗口。但主要问题是 for 循环中的单个图像显示。它显示循环中所有可用的图像。请建议我最好的解决方案。
这是我的 index.blade.php
文件,我尝试使用此代码显示滑块。
<div class="container-fluid margin-gallery d-lg-block d-block position-relative">
<div class="row">
<div class="col-lg-12 p-0">
<div class="demo-gallery">
@php
if($propertys->propertyImage!=null){
$images = json_decode($propertys->propertyImage->image_path, true);
}
else{
$images=null;
}
@endphp
<?php
$images_prop = collect($images['property_images']);
?>
<ul id="lightgallery">
@if($images['property_images']!=null)
@forelse($images_prop as $img)
<li class="sizing-li position-relative" data-src="{{ asset($img) }}">
<a href="javascript:void()">
<img class="img-responsive" src="{{ asset($img) }}" style="width:929px; height:495px;">
</a>
</li>
@empty
@endforelse
@endif
</ul>
</div>
</div>
</div>
</div>
我想在这里显示 for 循环的第一张图像
<img class="img-responsive" src="{{ asset($img) }}" style="width:929px; height:495px;">
I am trying to display the single image in the slider, but whenever the user will click on this then it's open a popup in data-src="multiple-images-here"
where I am running the slider. But the main issue is with the single image display in for loop. It displays all the available images in the loop. Please suggest me the best solution for this.
Here is my index.blade.php
file where I am trying to display the slider using this code.
<div class="container-fluid margin-gallery d-lg-block d-block position-relative">
<div class="row">
<div class="col-lg-12 p-0">
<div class="demo-gallery">
@php
if($propertys->propertyImage!=null){
$images = json_decode($propertys->propertyImage->image_path, true);
}
else{
$images=null;
}
@endphp
<?php
$images_prop = collect($images['property_images']);
?>
<ul id="lightgallery">
@if($images['property_images']!=null)
@forelse($images_prop as $img)
<li class="sizing-li position-relative" data-src="{{ asset($img) }}">
<a href="javascript:void()">
<img class="img-responsive" src="{{ asset($img) }}" style="width:929px; height:495px;">
</a>
</li>
@empty
@endforelse
@endif
</ul>
</div>
</div>
</div>
</div>
I want to display the first image from for loop here
<img class="img-responsive" src="{{ asset($img) }}" style="width:929px; height:495px;">
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以通过
->first()
函数仅获取 1 张图像,它将仅显示数据库中数据中的第一项。You can pass
->first()
function to get only 1 images, It will show you only the first item from your data in database.