這是回圈時的示例
盡管有太多的條件和關系,但似乎情況
@foreach (\App\ClientDocument::where('id_client', $clients->id)->get() as $item)
@if (\App\Document::where('id',$item->id_document)->get())
<a class="img-fluid " href="{{asset('images/'.$item->file)}}" download="{{asset('images/'.$item->file)}}" alt="Laravel - 在條件內回圈時元素顯示兩次" name="download" > Telecharger </a>
@endif
@endforeach
uj5u.com熱心網友回復:
在上面的片段中
@foreach (\App\ClientDocument::where('id_client', $clients->id)->get() as $item)
@if (\App\Document::where('id',$item->id_document)->get())
<a class="img-fluid " href="{{asset('images/'.$item->file)}}" download="{{asset('images/'.$item->file)}}" alt="Laravel - 在條件內回圈時元素顯示兩次" name="download" > Telecharger </a>
@endif
@endforeach
代碼絕對沒問題,但可能有可能,您正在使用重復資料運行,您也可以使用它。
\App\ClientDocument::where('id_client', $clients->id)->distinct('id_client')->get()
而不是使用 @if (\App\Document::where('id',$item->id_document)->get())
您可以使用
@if (\App\Document::where('id',$item->id_document)->firstOrFail())
@if (\App\Document::where('id',$item->id_document)->count())
就是這樣。
uj5u.com熱心網友回復:
首先你不應該在刀片檔案中加載資料在控制器函式中做然后你應該在 ClientDocument 模型名稱檔案中創建關系,在你的刀片中你可以執行 $item->document 或任何你想要的
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/338082.html
標籤:拉拉维尔 if 语句 laravel-5 雄辩 while 循环
