laravel的paginate()分页,如果用post传参,点击第二页时会默认使用get,就会返回原始数据了

需要把查询数据get方式也放到paginate()分页参数中

一、路由

Route::group(['prefix'=>'help'], function (){
Route::get('/pickup/{id}', 'TaskHelpController@pickupList'); //拾金不昧
}); //id是区分1帮助他人2寻求帮助

 

二、视图

                <div class="ibox-content">
<div class="row">
<div class="col-sm-12">
<div class="ibox float-e-margins">
<div class="ibox-content">
<form id="form_condition" class="form-search" method="get" action="{{ url('admin/help/pickup', ['id' => $is_type]) }}">
<div class="text-c ">
物品名称:
<select name="pickup_goods" class="form-control inline" id="pickup_goods" style="width:200px;">
{{--1拾金不昧 => 1钥匙 2钱包 3手机 4证件 5宠物 6其他--}}
<option value="">物品-请选择</option>
<option value="1">钥匙</option>
<option value="2">钱包</option>
<option value="3">手机</option>
<option value="4">证件</option>
<option value="5">宠物</option>
<option value="6">其他</option>
</select> 任务状态:
<select name="status" class="form-control inline" id="status" style="width:200px;">
{{--任务状态 1:待接单 2:已接单 3:已完成--}}
<option value="">状态-请选择</option>
<option value="1">待接单</option>
<option value="2">已接单</option>
<option value="3">已完成</option>
</select> <input type="text" class="form-control " id="id" style="width:150px;display: inline-block"
placeholder="ID搜索" name="id" value="">
<input type="text" class="form-control " id="phone" style="width:150px;display: inline-block"
placeholder="手机号搜索" name="phone" value="">
{{--<input type="text" class="form-control " id="key_name" style="width:150px;display: inline-block"--}}
{{--placeholder="昵称搜索" name="key_name" value="">--}}
<input type="text" class="form-control " id="title" style="width:150px;display: inline-block"
placeholder="事情搜索" name="title" value="">
<input type="text" class="form-control " id="content" style="width:150px;display: inline-block"
placeholder="事情经过搜索" name="content" value=""> <button class="btn btn-info " name="" type="submit">
<i class="fa fa-search"></i> 搜索
</button>
<a class="btn btn-default " href="{{ url('admin/help/pickup', ['id' => $is_type]) }}">
<i class="fa fa-times"></i> 清空搜索
</a>
</div>
</form>
</div>
</div>
</div>
</div> <table class="table table-striped table-bordered table-hover dataTables-example">
<thead>
<tr>
<th>ID</th>
<th>发布人</th>
<th>电话</th>
<th>拾取物品名称</th>
<th>主图</th>
<th>附属图</th>
<th>事发时间</th>
<th>事发地点</th>
<th>事情</th>
<th>事情经过</th>
<th>佣金</th>
<th>任务状态</th>
<th>创建时间</th>
<th>更新时间</th>
<th>操作</th>
</tr>
</thead>
<tbody>
@foreach ($pickupList as $p)
<tr class="gradeX">
<td class="center">{{ $p->id }}</td>
<td class="center">{{ $p->userInfo->name }}</td>
<td class="center">{{ $p->phone }}</td>
<td class="center">
@if($p->pickup_goods == 1)
钥匙
@elseif($p->pickup_goods == 2)
钱包
@elseif($p->pickup_goods == 3)
手机
@elseif($p->pickup_goods == 4)
证件
@elseif($p->pickup_goods == 5)
宠物
@else
其他
@endif
</td>
<td class="center">
@if($p->pic)
<a href="{{ $p->pic }}" target="_blank">
<img src="{{ $p->pic }}" width="30px" height="30px">
</a>
@else
暂无图片
@endif
</td>
<td class="center">
@if($p['otherPic'])
@foreach ($p['otherPic'] as $i)
<a href="{{ $i['img'] }}" target="_blank">
<img src="{{ $i['img'] }}" width="30px" height="30px">
</a>
@endforeach
@else
暂无图片
@endif
</td>
<td class="center">{{ $p->time }}</td>
<td class="center">{{ $p->address }}</td>
<td class="center">{{ $p->title }}</td>
{{--<td class="center">{{ str_limit($p->content,50,'...') }}</td>--}}
<td class="center">{{ $p->content }}</td>
<td class="center">{{ $p->commission }}</td>
<td class="center">
@if ($p->status == 3)
<span class="label label-primary">已完成</span>
@elseif ($p->status == 2)
<span class="label label-warning">已接单</span>
@else
<span class="label">待接单</span>
@endif
</td>
<td class="center">{{ $p->created_at }}</td>
<td class="center">{{ $p->updated_at }}</td>
<td class="center">
<button class="btn btn-default btn-sm" onclick="del( {{ $p->id }} );">删除</button>
</td>
</tr>
@endforeach
</tbody>
</table>
<div class="right">
{{ $pickupList->appends($cond)->links() }}
</div>
</div>

  

{{ $pickupList->appends($cond)->links() }}
//$cond 是查询参数

 


三、控制器
 /**
* 拾金不昧列表
*/
public function pickupList($id)
{ $condition = [];
$cond = []; //1钥匙 2钱包 3手机 4证件 5宠物 6其他
if(!empty($_GET['pickup_goods'])){
array_push($condition, ["pickup_goods", "=", $_GET['pickup_goods']]);
$cond['pickup_goods'] = $_GET['pickup_goods'];
} //任务状态 1:待接单 2:已接单 3:已完成
if(!empty($_GET['status'])){
array_push($condition, ["status", "=", $_GET['status']]);
$cond['status'] = $_GET['status'];
} //keyword
if(!empty($_GET['id'])){
array_push($condition, ["id", "=", $_GET['id']]);
$cond['id'] = $_GET['id'];
}
if(!empty($_GET['phone'])){
array_push($condition, ["phone", "like", "%{$_GET['phone']}%"]);
$cond['phone'] = $_GET['phone'];
}
if(!empty($_GET['title'])){
array_push($condition, ["title", "like", "%{$_GET['title']}%"]);
$cond['title'] = $_GET['title'];
}
if(!empty($_GET['content'])){
array_push($condition, ["content", "like", "%{$_GET['content']}%"]);
$cond['content'] = $_GET['content'];
} $pickupList = Pickup::with(['userInfo','otherPic'])
->where('Initiator_role', $id)
->where($condition)
->orderBy('id', 'desc')
->paginate(5); return view('admin.help.pickup_list', ['pickupList' => $pickupList, 'is_type' => $id, 'cond'=>$cond]);
}
'cond'=>$cond  //查询参数也要传过去

  

效果:

Laravel5.6---搜索查询 自带paginate()分页 get传参的更多相关文章

  1. 分页条件传参bug之解决

    问题描述:以对象作为参数,对象中包含PageNum.PageSize.Condition对象等.对应的@RequestBody为如PageReqDTO reqDTO时,如果使用postman时,不在b ...

  2. thinkphp 使用paginate分页搜索带参数

    最近做项目发现使用paginate分页,搜索的时候点下一页搜索条件就变没了,所以在网上找了找一些方法,有的说是使用Page类,但是用习惯了paginate,再用Page不习惯,找到了一个方法,可以使用 ...

  3. springboot+thymeleaf+pageHelper带条件分页查询

    html层 <div> <a class="num"><b th:text="'共 '+ ${result.resultMap['pages ...

  4. thinkphp 带条件分页查询

    thinkphp 带条件分页查询:form表单传值时候,method='get'. 用 get 传值

  5. CodeIgniter框架多条件搜索查询分页功能解决方案

    最近在用ci框架写功能的时候,需要用到分页功能,本来寻常的数据结果分页是比较简单的,但是这次写的功能是多条件搜索查询分页,就有点难度了,看官方手册下面评论好多人问, 正常的分页功能例子是这样的: $t ...

  6. grails框架的g:paginate分页标签的使用

    我用到的grails是2.4.4. 该版本下游一个标签g:paginate 该标签下有以下几个参数:total(必须要填写的项).controller.action.prev.max.offset等等 ...

  7. ThinkPHP3.2.3自带的分页用法--很简单实用

    把解压后的Page.class.php放入ThinkPHP/Extend/Library/ORG/Util/(如果没有请手动创建)目录下面.thinkphp 自带的分页非常好用美观,先看一下如下代码片 ...

  8. php--yii框架中的ajax分页与yii框架自带的分页

    要想使用Yii分页类 第一步:在控制器层加载分页类 use yii\data\Pagination; 第二步: 使用model层查询数据,并用分分页,限制每页的显示条数 $data = Zhao::f ...

  9. Ecmall系统自带的分页功能

    在Ecmall的二次开发中,分页是必不可少的.这个系统已经自带了分页功能,下面来看看如何使用这个分页. 下面是一个自定义的类,用于查看订单的详细情况.关键在于get_order_data()这个方法, ...

随机推荐

  1. Multi-Agent Reinforcement Learning Based Frame Sampling for Effective Untrimmed Video Recognition

    Multi-Agent Reinforcement Learning Based Frame Sampling for Effective Untrimmed Video Recognition IC ...

  2. 在本地搭建hyperledger fabric 网络

    参考了官方文档,直接就可以了https://hyperledger-fabric.readthedocs.io/en/latest/build_network.html 很好用 ➜ ~ cd $GOP ...

  3. Linux中root用户找不到JAVA_HOME

    Linux中root用户找不到JAVA_HOME   在Ubuntu环境中安装好Java环境后设置环境变量:在/etc/profile中设置好了JAVA_HOME变量并引入到PATH中,用于Ubunt ...

  4. 利用lsof命令查找已经删除的文件来释放磁盘空间

    测试环境一台服务器/目录空间使用率达到97%,但是通过du -sh *发现实际空间没用到那么多,初步怀疑,之前删除的文件,有运行中的进程一直占用,导致空间没有释放,如图通过du -sh *发现共实际使 ...

  5. [转]c++ pthread 多线程简介

    链接:https://blog.csdn.net/u013894427/article/details/83827173 pthread 入口函数类型说明void * func1(void * t)v ...

  6. phpexcel中文手册(转)

    首先到phpexcel官网上下载最新的phpexcel类,下周解压缩一个classes文件夹,里面包含了PHPExcel.php和PHPExcel的文件夹,这个类文件和文件夹是我们需要的,把class ...

  7. [LeetCode] 407. Trapping Rain Water II 收集雨水 II

    Given an m x n matrix of positive integers representing the height of each unit cell in a 2D elevati ...

  8. python+lego ev3的心得总结 随时更新

    一.连接方面 1.试了蓝牙连接,被电脑防火墙拒绝了很多次,很奇怪,明明都pin码都对上了,然后瞬间被踢开. 2.数据线直连,在一台win7上怎么试也不行,在另一台上自动上windows update上 ...

  9. Kubernetes 配置管理 ConfigMap(十二)

    目录 一.背景 二.创建 ConfigMap 2.1.通过 --from-literal 2.2.通过 --from-file 2.3.通过--from-env-file 2.4.YAML 配置文件 ...

  10. MySQL之表日志管理

    MySQL日志管理 mysql日志(默认存放在datadir): 同大多数关系型数据库一样,日志文件是MySQL数据库的重要组成部分.MySQL有几种不同的日志文件,通常包括错误日志文件,二进制日志, ...