【发布时间】:2019-10-22 16:43:46
【问题描述】:
我正在从控制器函数及其工作(通过 ajax)返回表视图。但想在'tr'标签上方使用foreach。但不知道怎么用。
-
返回 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; } -
制作 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; }
【问题讨论】: