laravel8 搜索后高亮显示

这是一个关于用户管理的视图和控制器代码示例。页面包含一个表单用于搜索会员,用户可以根据姓名、电话或邮箱进行查找。表格展示搜索结果,包括ID、真实名、用户名、性别、手机、邮箱、加入时间和状态等信息,并提供修改、分配权限和删除等操作。后台的搜索功能通过`withTrashed()`包含了被软删除的用户,并在结果中高亮显示搜索关键词。
摘要由CSDN通过智能技术生成

表单 

        <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">&#xe665;</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'));
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

.海上月

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值