我真的搞不清楚什麼是最好的標題,但這是我想要實現的。創建一些像ol(html),但取決於搜索結果
我想要做的就是讓第一列像html中的'ol'那樣對搜索結果進行編號。
我有這個在我的刀鋒:
<table class="table table-bordered" style="text-align: left;">
<tr>
<th>Full Name (Last, First, Middle)</th>
<th>Encoded by</th>
</tr>
<tbody>
{!! $searchresults !!}
</tbody>
</table>
這是我的控制器
public function listofStaffTable(){
$staffs = DB::table('staff_profiles')->select('last_name','first_name','middle_name','encoded_by')->orderBy('last_name','ASC')->get();
$searchresults = ""; // define the searchresults variable
foreach($staffs as $key => $profile){
$searchresults .= '<tr>'.
'<td><a href="'. URL::route('viewstaffprofile', $profile->id) .'">'. $profile->last_name .' '. $profile->first_name .' '. $profile->middle_name .' </a></td>'.
'<td>'. $profile->encoded_by .'</td>'.
</tr>';
}
$data = [];
$data['searchresults'] = $searchresults;
return view('user/masterlist/list-of-staffs', $data);
}
所以插入一個新的次代碼之後,我應該在我的控制器做。
這是使用Laravel 5.2的方式
謝謝!非常簡單:) –
這完全忽略了刀片的全部重點。你不應該把視圖特定的邏輯放在控制器中。 Blade有一個@foreach關鍵字,您可以像VikingCode的答案中指定的那樣使用它。 –
@RodneyZanoria @RodneyZanoria你的問題是「我應該在我的控制器中做什麼」而不是「我能做什麼」..你可以做什麼Erol提出的,但你應該做的是寫在我的回答 – VikingCode