用于返回Ajax响应的函数
public function displaySearch(Request $request)
{
$result = Team::where('name', $request->somthing)
->orwhere('order_id', $request->filter)->get();
$data = $this->make_ui($result);
return $data;
}
Make UI的私有功能
private function make_ui($result){
$data='';
foreach($result as $c){
$data.='<div class="table-responsive">
<table class="table table-striped table-bordered">
<thead>
<tr>
<th>Action</th>
<th>ID</th>
<th>Date</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr class="gradeX">
<td>'. $c->id .'</td>
<td>'. $c->order_id .'</td>
<td>'. $c->name .'</td>
<td>'. $c->role .'</td>
</tr>
</tbody>
<tfoot>
<tr>
<th>Action</th>
<th>ID</th>
<th>Date</th>
<th>Description</th>
</tr>
</tfoot>
</table>
</div>';
}
return $data;
}
答案 0 :(得分:1)
plz为我使用它的工作
private function make_ui($result){
$data='<div class="table-responsive">
<table class="table table-striped table-bordered">
<thead>
<tr>
<th>Action</th>
<th>ID</th>
<th>Date</th>
<th>Description</th>
</tr>
</thead>
<tbody>';
foreach($result as $c){
$data.='
<tr class="gradeX">
<td>'. $c->id .'</td>
<td>'. $c->order_id .'</td>
<td>'. $c->name .'</td>
<td>'. $c->role .'</td>
</tr>
';
}
$data .= '</tbody>
<tfoot>
<tr>
<th>Action</th>
<th>ID</th>
<th>Date</th>
<th>Description</th>
</tr>
</tfoot>
</table>
</div>';
return $data;
}
答案 1 :(得分:0)
一个简单的解决方案是分别连接它们。虽然我不确定这是否是最佳解决方案。 您可以尝试以下操作:
private function make_ui($result){
$data.='<div class="table-responsive">
<table class="table table-striped table-bordered">
<thead>
<tr>
<th>Action</th>
<th>ID</th>
<th>Date</th>
<th>Description</th>
</tr>
</thead>
<tbody>';
foreach($result as $c){
$data.='<tr class="gradeX">
<td>'. $c->id .'</td>
<td>'. $c->order_id .'</td>
<td>'. $c->name .'</td>
<td>'. $c->role .'</td>
</tr>';
}
$data.='</tbody>
<tfoot>
<tr>
<th>Action</th>
<th>ID</th>
<th>Date</th>
<th>Description</th>
</tr>
</tfoot>
</table>
</div>';
return $data;
}