筛选分页每页的条数:
路由:
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')
{{-- 表格内容 --}}
用户ID
用户电话
用户邮箱
用户名
用户昵称
注册时间
操作
@if ($data->total()>0)
@foreach ($data as $element)
{{-- {{dd($element)}} --}}
{{$element->id}}
{{$element->phone}}
{{$element->email}}
{{$element->user_name}}
{{$element->nick_name}}
{{$element->create_time}}
id] )}}" rel="external nofollow" >详细
id] )}}" rel="external nofollow" >修改
id] )}}" rel="external nofollow" >删除
@endforeach
{!! $data->render() !!}
@else
没有查到相关数据!
@endif
@endsection带筛选的: