Laravel 实现搜索的时候分页并携带参数

Spoony 66.55m2022-06-011001 次点击
```
$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)->appends(array(
'search' => $search,
'customer_type' => $customer_type,
'perPage' => $perPage,
));
```
收藏 ♥ 感谢
暂无回复

登录注册 后可回复。



GitHub