[英]Laravel, get info from another table inside foreach loop
I have foreach loop that get info from 'items' table from db.我有 foreach 循环从 db 的“项目”表中获取信息。
@foreach($puzzles->chunk(4) as $items)
<div class="row">
@foreach($items as $key => $data)
<div class="col-sm">
<div class="card" style="width: 18rem;">
<img class="card-img-top" src="http://localhost/beta/public/thumbnails/{{$data->avatar}}" alt="Card image cap">
<div class="card-body">
<h5 class="card-title">Card title</h5>
<span class="badge badge-primary">{{$data->maker}}</span>
<span class="badge badge-primary">{{$data->count}} pcs</span>
<p class="card-text">{{$data->location}}</p>
<div class="dropdown">
<button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Offer Exchange
</button>
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
@foreach($items as $key => $data)
@if($data->uid = '1')
<a class="dropdown-item" href="#">{{ $data->id }}</a>
@endif
@endforeach
</div>
</div>
</div>
</div>
</div>
@endforeach
</div>
@endforeach
So i tried to do like this所以我试着这样做
@foreach($items as $key => $data)
@if($data->uid = '1')
<a class="dropdown-item" href="#">{{ $data->id }}</a>
@endif
@endforeach
But as you imagine this does not work但正如你想象的那样,这行不通
So i have table ITEMS, where i can get all the data out what i need.所以我有表格项目,我可以在其中获取我需要的所有数据。
Then i have a button that has a dropdown and on that dropdown it should show the ITEMS that the user own, but for that i need the USER ID to check if ITEMS UID(UsersID) is the same as USER ID然后我有一个带有下拉列表的按钮,在该下拉列表中它应该显示用户拥有的项目,但为此我需要用户 ID 来检查项目 UID(用户 ID)是否与用户 ID 相同
And then display the outcome on that dropdown.然后在该下拉列表中显示结果。
Dump $data
and see what it returns object or array.转储
$data
并查看它返回 object 或数组的内容。 Also why not loop like this还有为什么不这样循环
@foreach($items as $item)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.