表单
<form action="" method="get">
<input type="text" onfocus="WdatePicker({ maxDate:'#F{$dp.$D(\'datemax\')||\'%y-%M-%d\'}' })" id="datemin" class="input-text Wdate" style="width:120px;">
<input type="text" onfocus="WdatePicker({ minDate:'#F{$dp.$D(\'datemin\')}',maxDate:'%y-%M-%d' })" id="datemax" class="input-text Wdate" style="width:120px;">
<input type="text" name="name" class="input-text" style="width:250px" placeholder="输入会员名称、电话、邮箱" id="">
<button type="submit" class="btn btn-success radius" id="" name=""><i class="Hui-iconfont"></i> 搜用户</button>
</form>
视图
<table class="table table-border table-bordered table-hover table-bg table-sort">
<thead>
<tr class="text-c">
<th width="25"><input type="checkbox" name="" value=""></th>
<th width="30">ID</th>
<th width="100">真实名</th>
{{-- <th width="100">角色</th>--}}
<th width="100">用户名</th>
<th width="40">性别</th>
<th width="90">手机</th>
<th width="150">邮箱</th>
<th width="130">加入时间</th>
<th width="70">状态</th>
<th width="150">操作</th>
</tr>
</thead>
<tbody>
@foreach($data as $item)
<tr class="text-c">
<td>
@if(auth()->id() != $item->id)
@if($item->deleted_at == null)
<input type="checkbox" value="{{ $item->id }}" name="id[]">
@endif
@endif
</td>
<td>{{ $item->id }}</td>
<td>{!! $item->truename !!}</td>
{{-- <td>{{ $item->role->name }}</td>--}}
<td>{{ $item->username }}</td>
<td>{{ $item->sex }}</td>
<td>{{ $item->phone }}</td>
<td>{{ $item->email }}</td>
<td>{{ $item->created_at }}</td>
<td class="td-status"><span class="label label-success radius">已启用</span></td>
<td class="td-manage">
<a href="{{ route('user.role',$item) }}" class="label label-secondary radius">分配权限</a>
{{-- {!! $item->editBtn('admin.user.edit') !!}--}}
{{-- @if(auth()->id() != $item->id)--}}
{{-- @if($item->deleted_at != null)--}}
{{-- <a href="{{ route('admin.user.restore',['id'=>$item->id]) }}" class="label label-warning radius">还原</a>--}}
{{-- @else--}}
{{-- {!! $item->deleteBtn('admin.user.del') !!}--}}
{{-- @endif--}}
{{-- @endif--}}
<a href="{{route('admin.user.edit',['id'=>$item->id])}}" class="label label-secondary radius">修改</a>
@if(auth()->id()!=$item->id)
@if($item->deleted_at!=null)
<a href="{{route('admin.user,restore',['id'=>$item->id])}}" class="label label-primary ">还原</a>
@else
<a href="{{route('admin.user.del',['id'=>$item->id])}}" class="label label-danger radius delbtn">删除</a>
@endif
@endif
</td>
</tr>
@endforeach
</tbody>
</table>
{{-- 分页 支持搜索功能 --}}
{{ $data->appends(request()->except('page'))->links() }}
搜索后 替换 并保留条件分页
public function index(Request $request) {
$name=$request->get('name');
// var_dump($name);
// 分页 withTrashed 显示所有的,包括已经进行了软删除的
$data = User::orderBy('id', 'asc')->withTrashed()->
where('truename','like','%'.$name.'%')->paginate($this->pagesize);
foreach ($data as $key=>$v){
if($v['truename']){
$v['truename']=str_replace($name,"<b style='color: red'>$name</b>",$v['truename']);
}
}
return view('admin.user.index', compact('data'));
}