我正在嘗試在滑塊中顯示單個影像,但是每當用戶單擊它時,它就會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 hljs-string">" 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;">
uj5u.com熱心網友回復:
您可以通過->first()函式僅獲取 1 張影像,它只會顯示資料庫中資料的第一項。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/451164.html
標籤:php 拉拉维尔 laravel-5 看法 laravel-8
下一篇:通過表單將id傳遞給外鍵
