1. 程式人生 > 其它 >laravel7 搜尋關鍵字標紅及手機號,身份證號隱藏

laravel7 搜尋關鍵字標紅及手機號,身份證號隱藏

控制器程式碼
 public function index(Request $request)
    {
        //接受搜尋關鍵字
        $word = $request->get('name');
        $start = $request->get('start');
        $end = $request->get('end');
        $paginsete = config('setting.paginate');
        $data = Register::where('name', 'like', "%$word%
")->whereNotBetween('created_at', [$start, $end])->orderBy('id', 'desc')->paginate($paginsete); $where = []; $where['word'] = $word; $where['start'] = $start; $where['end'] = $end; return view('register.index', compact('data', 'where','word')); }
檢視程式碼:
 @foreach($data 
as $item) <tr class="text-c"> <td><input type="checkbox" value="{{$item->id}}" name="id[]"></td> <td>{{$item->id}}</td> <td><u style="cursor:pointer" class="text-primary">{!!str_replace($where
['word'], "<span style='color:red'>{$where['word']}</span>", $item->name) !!}</u></td> <td>{{$item->Job_number}}</td> <td>{{substr_replace($item->id_number,'****',6,8)}}</td> <td>{{substr_replace($item->phone,'****',4,4)}}</td> <td class="text-l">{{$item->Department}}</td> <td>{{$item->created_at}}</td> <td class="td-status"><span class="label label-success radius"> @if($item->status==0) 已就診 @elseif($item->status==1) 未就診 @else 未掛號 @endif </span></td> <td class="td-manage"><a style="text-decoration:none" onClick="member_stop(this,'10001')" href="javascript:;" title="停用"><i class="Hui-iconfont">&#xe631;</i></a> <a title="編輯" href="javascript:;" onclick="member_edit('編輯','member-add.html','4','','510')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6df;</i></a> <a style="text-decoration:none" class="ml-5" onClick="change_password('修改密碼','change-password.html','10001','600','270')" href="javascript:;" title="修改密碼"><i class="Hui-iconfont">&#xe63f;</i></a> <a title="刪除" href="javascript:;" onclick="member_del(this,'1')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6e2;</i></a></td> </tr> @endforeach

效果圖: