0
我有一個關聯數組$ $集合和一個索引數組$ gnd,我已經從Controller傳遞到Laravel 5.2中的view.blade.php。我想打印這兩個數組的值在一個表中。這是我的代碼,在laravel5.2中view.blade.php中打印索引數組值
<table class="responsive-table highlight centered">
<thead>
<tr>
<th data-field="id">Sl.no</th>
<th data-field="name">Unique </th>
<th>Name</th>
<th data-field="price">Description</th>
<th>Gender</th>
</tr>
</thead>
<tbody>
{{-- */$j = 1;/* --}}
@foreach($collection as $key=>$value)
<tr>
<td>{{ $j }}</td>
<td>{{ $value->uid }}</td>
<td>{{ $value->name }}</td>
<td>{{ $value->desc }}</td>
<td>{{ $gnd[$j] }}</td>
{{-- */$j++;/* --}}
@endforeach
</tr>
</tbody>
</table>
對於{{$ gnd [$ j]}}我得到以下錯誤。
ErrorException in b7c1ab515a44988c31e1982a3ce014434e97ef2c.php line 30:
Undefined offset: 22 (View: /var/www/html/anudip/resources/views/plugins/entries/view.blade.php)
我是laravel的新人。請幫我...
功能,從控制器通過兩個數組:
public function getDetails(){
$collection = DB::table('entry_transactions')
->leftJoin('entry_masters', 'entry_transactions.entry_id', '=', 'entry_masters.id')
->get(['entry_masters.id as uid','entry_masters.name as name','entry_masters.gender as gender','entry_transactions.entry_desc as desc']);
$gnd = array();
$len = sizeof($gnd);
$i = 0;
foreach ($collection as $key) {
if($key->gender == 0){
$gnd[$i] = "Male";
}
else {
$gnd[$i] = "Female";
}
$i++;
}
return view($this->url.'entries.view', compact('collection','gnd'));
}
感謝theMohammadA。有效。我顯示了我的控制器通過了兩個陣列。再次感謝... –
不客氣:) – theMohammedA