laravel做查詢 做查詢時的分頁判斷
阿新 • • 發佈:2018-12-08
檢視頁面
<form action="{{url('consultshow')}}" method="post"> <tr> <td colspan="5"> <input type="submit" value="查詢" class="btn" > <input type="text" placeholder="請輸入標題" name="con_titil" style="margin-top:13px;"> </td> </tr> </form>
控制器書寫
// 查詢 public function consultshow(){ // 獲取name值 $name = $_POST["con_titil"]; // 模糊查詢 $info = DB::select("select * from hy_newlist where con_titil like '%{$name}%' "); // var_dump($data);die(); return view('consult.consultindex',['info'=>$info]); } }
因為這個也是返回到同樣的檢視 而且還是分頁 所以需要在前臺頁面使用判斷
@if(isset($data)) @foreach($data as $v) <tr> <td><input type="checkbox" value="{{$v->id}}" name="box"></td> <td>{{$v->id}}</td> <td>@if($v->type_status==1)新聞@elseif($v->type_status==2)公告@else產品 @endif</td> <td>{{$v->con_titil}}</td> <td>{{$v->con_date}}</td> <td>@if($v->con_status==1)顯示@else不現實@endif</td> <td>{{$v->con_text}}</td> <td><a href="consult_del?id={{$v->id}}" class="btn btn-danger"><i class="icon-trash" style="margin-right:3px"> 刪除</i></a></td> </tr> @endforeach @endif @if(isset($info)) @foreach($info as $v) <tr> <td><input type="checkbox" value="{{$v->id}}" name="box"></td> <td>{{$v->id}}</td> <td>@if($v->type_status==1)新聞@elseif($v->type_status==2)公告@else產品 @endif</td> <td>{{$v->con_titil}}</td> <td>{{$v->con_date}}</td> <td>@if($v->con_status==1)顯示@else不現實@endif</td> <td>{{$v->con_text}}</td> <td><a href="consult_del?id={{$v->id}}" class="btn btn-danger"><i class="icon-trash" style="margin-right:3px"> 刪除</i></a></td> </tr> @endforeach @endif </tbody> <tr> @if(!isset($info)) <td id="pull_right"colspan="8">{{$data->render('page')}}</td> @endif