laravel 做搜尋查詢時 遇見無限極分類判斷【發給自己看的】
阿新 • • 發佈:2018-12-08
檢視
<form action="{{url('navshow')}}" method="post"> <tr> <td colspan="5"> <input type="submit" value="查詢" class="btn" > <input type="text" placeholder="請輸入類名稱" name="nav_name" style="margin-top:13px;"> </td> </tr> </form> <tr> <th>選擇</th> <th>導航id</th> <!-- <th style="display: none;">是否警用</th> --> <th>導航名稱</th> <th>導航分類</th> <th>導航連結地址</th> <th>操作</th> </tr> </thead> <tbody> @foreach($data as $v) <tr> <td><input type="checkbox" value="{{$v->id}}" name="box"></td> <td>{{$v->id}}</td> <td>@if(isset($v->level)){{{str_repeat(' -',$v->level)}}}@endif {{$v->nav_name}}</td> <td>{{$v->pid}}</td> <td><a href="http://{{$v->nav_link}}">{{$v->nav_link}}</a></td> <td><a href="navdel?id={{$v->id}}" class="btn btn-danger"><i class="icon-trash" style="margin-right:3px"> 刪除</i></a></td> </tr> @endforeach </tbody>
控制器
// 查詢
public function navshow(){
$name = $_POST['nav_name'];
// 使用模糊查詢
$data =DB::select("select * from hy_privileges where nav_name like '%{$name}%' ");
return view('nav.navindex',['data'=>$data]);
}