Laravel实现搜索的时候分页并携带参数
筛选分页每页的条数:
选择class=' form-control ' id=' perPage ' name=' perPage ' @ foreach([10,20,30,50]作为$e)选项值=' { { $ e } } ' { $ e==请求(' perPage ')?已选择" : " } } { { $ e } }/option @ endforeach/select路由:
路由: get(' customer/index/{ customer _ type?} ','[电子邮件保护]');后端接口:
公共函数索引($ customer _ type=null){ $ search=request(' search ');$perPage=请求(“perPage”)?请求(' Perpage '): 10;$ customer _ type=$ customer _ type?$customer_type :请求(“customer _ type”);$ data=customer :3360 select([' id ',' email ',' user_name ',' nick_name ',' phone ',' create _ time '])-where(' customer _ type ','=',$ customer _ type)-where(function($ query)use($ search){ if($ search){ $ query-where(' user _ name ',' like ',' % ').$搜索% ')-or here(' nick _ name ',' like ',' % ' .$搜索% ')-或这里('电话',' like ',' % ' .$搜索% ')-或此处('电子邮件',' like ',' % ' .$搜索。'%');} }) -orderBy('create_time ',' desc ')-paginate($ perPage);//追加额外参数,例如搜索条件$ appendData=$ data-追加(数组(' search'=$search,' customer_type'=$customer_type,' perPage'=$perPage,返回视图(' admin/customerList ',compact(' data '));}##效果图:
前端完整代码:
@ extends(' admin。master()@ section(' content ')div class=' wrapper-content animated fadeInRight ' div class=' row ' div class=' col-sm-12 ' div class=' ibox float-e-margins ' form class=' form-inline ' method=' get ' action=' { { URL(/admin/customer/index ',[request()-route(' customer _ type ')])} } div class=' form-group ' style=' margin-left : 20px '标签每页显示数:/label select class=' form-control ' id=' perPage ' name=' perPage ' @ foreach([10,20,30,50]作为$e)选项值=' { { $ e } } ' { $ e==请求(' perPage ')? 选择" : " } } { { $ e } }/option @ endforeach/select/div class=" form-group " style=" margin-left : 20px "标签为="搜索"模糊搜索:/标签输入类型=' text ' name=' search ' style=' width : 400 px ' class=' form-control ' id=' search ' placeholder='请输入机构名或者邮箱或者电话value=' { { request(' search ')} } '/div button type=' submit ' class=' BTN BTN-primary ' style=' margin-left : 20px '开始搜索/button /form {{ -表格内容-} } div class=' ibox-content ' table class=' table table-hover table-bordered table-condentiate '和tr class=' success ' th class=' text-center '用户身份证/第类='文本中心'用户电话' th class='文本中心'用户邮箱' th class='文本中心'用户名' th class='文本中心'用户昵称' th class='文本中心'注册时间' th class='文本中心'操作/th/tr/thead @ if($ data-total()0)t body @ foreach($ data as $ element){-{ { DD($ element)} }-} } tr class=' gradeU {($ element[' status ']==4? BG-danger ' : ' ' } } ' TD { { $ element-id } }/TD TD class=' center ' { $ element-phone } }/TD { { $ element-email } }/TD { { $ element-user _ name } }/TD { { $ element-nick _ name } }/TD { $ element-create _ time } }/TD TD TD a class=' BTN BTN-info ' href=' { { URL(' admin/customer/getInfo ',[]详细/a a class=' BTNBTN-成功' href=' { { URL(' admin/customer/read customer ',[$ element-id])} } ' rel='外部无跟随'修改/a a class=' BTNBTN-危险' href=' { { URL(' admin/customer/softDeleteCustomer ',[$ element-id])} } ' rel='外部无跟随'删除/a/TD/tr @ endforeach/t body/table div class=' text-center ' { 0!$data-render()!}/div @ else t body tr TD col span=' 7 ' div class=' text-center ' H3没有查到相关数据!/H3/div/TD/tr/t正文/表格@ endif/div/div/div @ end section带筛选的:
form class='form-inline '方法='get '操作=' { { URL(' DataInfo/channel _ form _ data ',请求(' id ')} } ' div class=' form-group ' style=' margin-left : 20px '标签为='搜索'状态筛选:/标签选择name=' user _ status ' class=' form-control '选项所有状态/option @ foreach($ user _ status as $ key=$ element)选项值=' { { $ key } } ' { { request(' user _ status ')=$ key?选择" : " } } { { $ element } }/option @ endforeach/select label for=" search "模糊搜索:/标签输入类型=' text ' name=' search ' style=' width : 400 px ' class=' form-control ' id=' search ' placeholder='用户名或者邮箱value=' { {请求('搜索')} } /div按钮类型=' submit ' class=' BTN BTN-primary ' style=' margin-left : 20px '开始搜索/button a href=' { { URL(' DataInfo/create _ channel _ user _ data ',request(' id ')} ' } ' rel=' external no follow ' class=' BTN BTN-primary ' style=' float : right;' 新增渠道用户a/表单以上这篇Laravel实现搜索的时候分页并携带参数就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持我们。
版权声明:Laravel实现搜索的时候分页并携带参数是由宝哥软件园云端程序自动收集整理而来。如果本文侵犯了你的权益,请联系本站底部QQ或者邮箱删除。