laravel获取访问来路的函数(Laravel实现搜索的时候分页并携带参数)
类别:编程学习 浏览量:441
时间:2021-10-06 01:43:03 laravel获取访问来路的函数
Laravel实现搜索的时候分页并携带参数筛选分页每页的条数:
<select class="form-control" id="perPage" name="perPage"> @foreach ( [10,20,30,50] as $e) <option value="{{$e}}" {{ $e==request('perPage') ? 'selected' : '' }} >{{$e}}</option> @endforeach </select>
路由:
Route::get('customer/index/{customer_type?}', 'CustomerController@index');
后端接口:
public function index($customer_type = null) { $search = request('search'); $perPage = request('perPage') ? request('perPage') : 10; $customer_type = $customer_type ? $customer_type : request('customer_type'); $data = Customer::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', '%' . $search . '%') ->orWhere('nick_name', 'like', '%' . $search . '%') ->orWhere('phone', 'like', '%' . $search . '%') ->orWhere('email', 'like', '%' . $search . '%'); } }) ->orderBy('create_time', 'desc') ->paginate($perPage); //追加额外参数,例如搜索条件 $appendData = $data->appends(array( 'search' => $search, 'customer_type' => $customer_type, 'perPage' => $perPage, )); return view('admin/customerList', compact('data')); }
##效果图:
前端完整代码:
@extends('admin.master') @section('content') <li class="wrapper wrapper-content animated fadeInRight"> <li class="row"> <li class="col-sm-12"> <li class="ibox float-e-margins"> <form class="form-inline" method="get" action="{{ url('/admin/customer/index',[request()->route('customer_type')])}}"> <li class="form-group" style="margin-left: 20px"> <label for="perPage">每页显示数:</label> <select class="form-control" id="perPage" name="perPage"> @foreach ( [10,20,30,50] as $e) <option value="{{$e}}" {{ $e==request('perPage') ? 'selected' : '' }} >{{$e}}</option> @endforeach </select> </li> <li class="form-group" style="margin-left: 20px"> <label for="search">模糊搜索:</label> <input type="text" name="search" style="width: 400px" class="form-control" id="search" placeholder="请输入机构名或者邮箱或者电话" value="{{request('search')}}"> </li> <button type="submit" class="btn btn-primary" style="margin-left: 20px">开始搜索</button> </form> {{-- 表格内容 --}} <li class="ibox-content"> <table class="table table-hover table-bordered table-condensed"> <thead> <tr class="success"> <th class="text-center">用户ID</th> <th class="text-center">用户电话</th> <th class="text-center">用户邮箱</th> <th class="text-center">用户名</th> <th class="text-center">用户昵称</th> <th class="text-center">注册时间</th> <th class="text-center">操作</th> </tr> </thead> @if ($data->total()>0) <tbody> @foreach ($data as $element) {{-- {{dd($element)}} --}} <tr class="gradeU {{ ($element['status']==4)?'bg-danger':'' }}"> <td>{{$element->id}}</td> <td class="center">{{$element->phone}}</td> <td>{{$element->email}}</td> <td>{{$element->user_name}}</td> <td>{{$element->nick_name}}</td> <td>{{$element->create_time}}</td> <td> <a class="btn btn-info" href="{{ url('admin/customer/getInfo',[$element->id] )}}" rel="external nofollow" >详细</a> <a class="btn btn-success" href="{{ url('admin/customer/readCustomer',[$element->id] )}}" rel="external nofollow" >修改</a> <a class="btn btn-danger" href="{{ url('admin/customer/softDeleteCustomer',[$element->id] )}}" rel="external nofollow" >删除</a> </td> </tr> @endforeach </tbody> </table> <li class="text-center">{!! $data->render() !!}</li> @else <tbody> <tr ><td colspan="7"><li class="text-center"><h3>没有查到相关数据!</h3></li></td></tr> </tbody> </table> @endif </li> </li> </li> </li> </li> @endsection
带筛选的:
<form class="form-inline" method="get" action="{{ url('dataInfo/channel_form_data',request('id'))}}"> <li class="form-group" style="margin-left: 20px"> <label for="search">状态筛选:</label> <select name="user_status" class="form-control"> <option>所有状态</option> @foreach ($user_status as $key=>$element) <option value="{{$key}}" {{request('user_status')==$key?'selected':''}}>{{$element}}</option> @endforeach </select> <label for="search">模糊搜索:</label> <input type="text" name="search" style="width: 400px" class="form-control" id="search" placeholder="用户名或者邮箱" value="{{request('search')}}"> </li> <button type="submit" class="btn btn-primary" style="margin-left: 20px">开始搜索</button> <a href="{{url('dataInfo/create_channel_user_data',request('id'))}}" rel="external nofollow" class="btn btn-primary" style="float:right;">新增渠道用户</a> </form>
以上这篇Laravel实现搜索的时候分页并携带参数就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。
原文链接:https://blog.csdn.net/zhezhebie/article/details/78285214
您可能感兴趣
- sqlserver修改排序规则几种方法(SQL Server 分页编号的另一种方式推荐)
- sqlserver分页查询sql语句(sql server实现分页的方法实例分析)
- sqlserver小结(基于sqlserver的四种分页方式总结)
- mysql的分页原理(mysql分页的limit参数简单示例)
- css简单网页布局代码(纯CSS制作自适应分页条附源码下载)
- mysql 高效分页(MySQL 分页查询的优化技巧)
- vue和springboot分页开发实现(解决Vue+SpringBoot+Shiro跨域问题)
- thinkphp5如何实现消息队列(thinkPHP5.1框架使用SemanticUI实现分页功能示例)
- dedecms文章顺序(dedecms 分页标题提取方法)
- vue加element ui弹窗(Vue中ElementUI分页组件Pagination的使用方法)
- javascript组件库实现(JavaScript分页组件使用方法详解)
- mongodb 分页查询
- sql语句实现分页(SQL 窗口函数实现高效分页查询的案例分析)
- dedecms列表分页无法显示(dedecms 5.6 分页样式代码修改方法)
- dedecms分页修改(dedecms 自动审核会员发表的最新文章的修改方法)
- laravel前后端分离实现排序(laravel自定义分页的实现案例offset和limit)
- 一天一冲也算表 麦步,一款待机 21 天的智能手表体验评测(一天一冲也算表)
- 魅族智能手表充电座曝光 Type-C 接口,线座分离设计(魅族智能手表充电座曝光)
- 华为 Watch GT2 Pro 智能手表曝光,新增支持无线充电(华为WatchGT2)
- vivo首款智能手表来了 也有血氧饱和度监测,一次充电18天续航(vivo首款智能手表来了)
- 你知道 七夕 的真正含义吗(你知道七夕的真正含义吗)
- 七夕的寓意(七夕的寓意)
热门推荐
- laravel服务提供者应用场景(Laravel如何创建服务器提供者实例代码)
- css3常用特性(css3学习之2D转换功能详解)
- sql常遇到的问题(SQL语句执行超时引发网站首页访问故障问题)
- ASP.NET如何获取上传图片的宽和高
- php中怎么判断变量类型(PHP INT类型在内存中占字节详解)
- html5 页面向上滑动(html5手机键盘弹出收起的处理)
- jquery on绑定多个事件
- python怎样读取txt文件的数据内容(Python实现读取txt文件中的数据并绘制出图形操作示例)
- html5canvas画图有什么用(Html5基于canvas实现电子签名并生成PDF文档)
- myisam和innodb的区别
排行榜
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9