我試圖讓我在 Laravel 中的收藏如此顯示
1 2
3 4
每一個都顯示一個獨特的條目。
然而,顯示的條目在每一行上顯示一個唯一的條目,而不是我打算這樣做的方式,并顯示如下:
1 1
2 2
這是我的代碼:
@forelse ($properties as $property)
<div class="mt-4 lg:gap-6 lg:flex lg:items-center lg:flex-wrap lg:mt-20">
<div class="p-4 bg-white rounded-lg">
<div class="p-6">
<h4 class="text-2xl font-bold cursor-pointer">
{{$property->address1}}
@if(!$property->address2==null)
,<br/>{{$property->address2}}
@endif
</h4>
<div class="mt-2">
<span class="text-xl font-extrabold text-blue-600">@money($property->valuation, 'ZAR')</span> /M
</div>
<div class="flex mt-2">
Tenant<br>
{{$property->user->name}}
</div>
</div>
<div class="flex justify-between p-4 text-gray-700 border-t border-gray-300">
<div class="flex items-center">
</div>
</div>
</div>
<div class="p-4 bg-white rounded-lg">
<div class="p-6">
<h4 class="text-2xl font-bold cursor-pointer">
{{$property->address1}}
@if(!$property->address2==null)
,<br/>{{$property->address2}}
@endif
</h4>
<div class="mt-2">
<span class="text-xl font-extrabold text-blue-600">@money($property->valuation, 'ZAR')</span> /M
</div>
<div class="flex mt-2">
Tenant<br>
{{$property->user->name}}
</div>
</div>
<div class="flex justify-between p-4 text-gray-700 border-t border-gray-300">
</div>
</div>
</div>
@empty
No Properties to show
@endforelse
任何幫助將不勝感激!
uj5u.com熱心網友回復:
這是一個代碼片段,它將1 2 3 4正確輸出。請基于此考慮您的 HTML 部分。
控制器:
$properties = collect([1,2,3,4]);
刀刃:
<link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/5.0.2/css/bootstrap.min.css" rel="stylesheet">
@forelse ($properties as $index=>$property)
@if ($index % 2 == 0)
<div class="row">
<div class="col">
{{$property}}
</div>
@else
<div class="col">
{{$property}}
</div>
</div>
@endif
@empty
No Properties to show
@endforelse
或者,您可以使用 laravel $loop變數
<link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/5.0.2/css/bootstrap.min.css" rel="stylesheet">
@forelse (collect([1,2,3,4]) as $property)
@if ($loop->odd)
<div class="row">
<div class="col">
{{$property}}
</div>
@else
<div class="col">
{{$property}}
</div>
</div>
@endif
@empty
No Properties to show
@endforelse
您可以在此處查看現場演示
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/364646.html
