我真的搞不清楚什么是最好的标题,但这是我想要实现的。创建一些像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