嵌套foreach
遇到问题,尽管还有其他问题,我无法理解我的Customers.blade
文件可能出错的地方:
@foreach ($customers as $company)
<tr>
<td></td>
<td>{{ $company->name }}</td>
<td>@if ($company->active == 1) YES @else NO @endif</td>
<td>View</td>
<td>Edit</td>
<td>Remove</td>
</tr>
@foreach ($customersites->customer_id as $company->id)
<tr>
<td></td>
<td>{{ $customersites->sitename }}</td>
<td>@if ($customersites->active == 1) YES @else NO @endif</td>
<td>View</td>
<td>Edit</td>
<td>Remove</td>
</tr>
@endforeach
@endforeach
这导致:
此集合实例上不存在属性[customer_id]。 (查看:&gt; C:\ Apache24 \ htdocs \ truckrun \ resources \ views \ customers.blade.php)
我做错了什么?
答案 0 :(得分:0)
请试试这个:
@foreach ($customers as $company)
<tr>
<td></td>
<td>{{ $company->name }}</td>
<td>@if ($company->active == 1) YES @else NO @endif</td>
<td>View</td>
<td>Edit</td>
<td>Remove</td>
</tr>
@foreach ($customersites as $company->id)
<tr>
<td></td>
<td>@if(isset($customersites->sitename) && $customersites->sitename !="") {{ $customersites->sitename }} @endif</td>
<td>@if ($customersites->active == 1) YES @else NO @endif</td>
<td>View</td>
<td>Edit</td>
<td>Remove</td>
</tr>
@endforeach
@endforeach