課程
/后端開發(fā)
/PHP
/輕松學(xué)會Laravel-表單篇
老師 搜索 后的 分頁 如何 做
我的 搜索 它能 顯示 我的 搜索后的條數(shù) 但點(diǎn)擊第二頁 時(shí)直接 回到全局的 page?
若 我在 地址欄 加上page=2就可正常 顯示 了?
2016-09-10
源自:輕松學(xué)會Laravel-表單篇 2-3
正在回答
模板中分頁的地方加上搜索的參數(shù),使用Request::input()方法即可,注意參數(shù)層級!
{{ $students->appends(Request::input())->render() }
老師 上面 是我問題 的代碼?
在同一頁面 展示
controller?
public function index(Request $request){ ? ?if (!empty($request['search'])) { ? ? ? ?$goods = Goods::where('tag', 'like', '%' . $request['search'] . '%')->paginate(10); ? ?} else { ? ? ? ?$goods = Goods::paginate(10); ? ?} ? ?$page_title = "商品列表"; ? ?$page_level = $this->page_level; ? ?return view('goods.index', compact('goods','page_title', 'page_level'));}
index.blade.php
<div class="row"> ? ?<div class="col-md-6"> ? ? ? ?<div class="box box-primary"> ? ? ? ? ? ?<form id="tagsearch" class="form-horizontal" action="{{URL::to('goods')}}" method="get" enctype="multipart/form-data"> ? ? ? ? ? ? ? ?<div class="box-header with-border"> ? ? ? ? ? ? ? ? ? ?<h3 class="box-title">{{$page_title or "Page Title"}}</h3> ? ? ? ? ? ? ? ? ? ?<input type="hidden" name="_token" value="{{csrf_token()}}"> ? ? ? ? ? ? ? ?</div> ? ? ? ? ? ? ? ?<div class="box-body"> ? ? ? ? ? ? ? ?</div> ? ? ? ? ? ? ? ?<div class="form-group"> ? ? ? ? ? ? ? ? ? ?<label for="name" class="col-sm-3 control-label">標(biāo)簽</label> ? ? ? ? ? ? ? ? ? ?<div class="col-sm-8"> ? ? ? ? ? ? ? ? ? ? ? ?<input type="text" class="form-control" id="search" name="search" placeholder="標(biāo)簽" value=""> ? ? ? ? ? ? ? ? ? ? ? ?@include('layouts.message.tips',['field'=>'name']) ? ? ? ? ? ? ? ? ? ?</div> ? ? ? ? ? ? ? ?</div> ? ? ? ? ? ? ? ?<div class="box-footer"> ? ? ? ? ? ? ? ? ? ?<a class="btn btn-default" href="{{route('goods.index')}}">返回</a> ? ? ? ? ? ? ? ? ? ?<button type="submit" class="btn btn-danger pull-right">搜索</button> ? ? ? ? ? ? ? ?</div> ? ? ? ? ? ?</form> ? ? ? ?</div> ? ?</div></div><div class="row"> ? ?<div class="col-md-12"> ? ? ? ?<div class="box"> ? ? ? ? ? ?<div class="box-header with-border"> ? ? ? ? ? ? ? ?<h3 class="box-title">商品信息列表</h3> ? ? ? ? ? ?</div> ? ? ? ? ? ?<div class="box-body table-responsive no-padding"> ? ? ? ? ? ? ? ?<table class="table table-hover"> ? ? ? ? ? ? ? ? ? ?<tr> ? ? ? ? ? ? ? ? ? ? ? ?<th>編號</th> ? ? ? ? ? ? ? ? ? ? ? ?<th>商品名稱</th> ? ? ? ? ? ? ? ? ? ? ? ?<th>標(biāo)簽</th> ? ? ? ? ? ? ? ? ? ? ? ?<th>地址</th> ? ? ? ? ? ? ? ? ? ? ? ?<th>價(jià)格</th> ? ? ? ? ? ? ? ? ? ? ? ?<th>發(fā)布時(shí)間</th> ? ? ? ? ? ? ? ? ? ? ? ?<th>管理操作</th> ? ? ? ? ? ? ? ? ? ?</tr> ? ? ? ? ? ? ? ? ? ?@forelse($goods as $goodinfo) ? ? ? ? ? ? ? ? ? ? ? ?<tr> ? ? ? ? ? ? ? ? ? ? ? ? ? ?<td>{{ $goodinfo['id'] }}</td> ? ? ? ? ? ? ? ? ? ? ? ? ? ?<td>{{ $goodinfo['name'] ?}}</td> ? ? ? ? ? ? ? ? ? ? ? ? ? ?<td>{{ $goodinfo['tag'] }}</td> ? ? ? ? ? ? ? ? ? ? ? ? ? ?<td>{{ $goodinfo['region'] }}</td> ? ? ? ? ? ? ? ? ? ? ? ? ? ?<td>{{ $goodinfo['price'] }}</td> ? ? ? ? ? ? ? ? ? ? ? ? ? ?<td>{{ $goodinfo['created_at'] }}</td> ? ? ? ? ? ? ? ? ? ? ? ? ? ?<td> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?<button class="btn btn-danger" data-toggle="modal" data-target="#defalutModal" data-url="{{URL::to('goods/'.$goodinfo['id'])}}"> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?@if($goodinfo['status']) 下架 @else 上架 @endif ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?</button> ? ? ? ? ? ? ? ? ? ? ? ? ? ?</td> ? ? ? ? ? ? ? ? ? ? ? ?</tr> ? ? ? ? ? ? ? ? ? ?@empty ? ? ? ? ? ? ? ? ? ? ? ?<tr> ? ? ? ? ? ? ? ? ? ? ? ? ? ?<td colspan="9" class="text-center">暫無數(shù)據(jù)</td> ? ? ? ? ? ? ? ? ? ? ? ?</tr> ? ? ? ? ? ? ? ? ? ?@endforelse ? ? ? ? ? ? ? ?</table> ? ? ? ? ? ?</div> ? ? ? ? ? ?@if($goods->render() !== "") ? ? ? ? ? ? ? ?<div > ? ? ? ? ? ? ? ? ? ?{!! $goods->render() !!} ? ? ? ? ? ? ? ?</div> ? ? ? ? ? ?@endif ? ? ? ?</div> ? ?</div></div>
舉報(bào)
Laravel框架是世界上最流行的PHP框架,沒有之一
1 回答頁面提交后保存老數(shù)據(jù) 單選框如何保存呢··
2 回答分頁的問題
1 回答5.2分頁的問題
3 回答分頁{{ $student->render() }}
2 回答請問老師,為啥分頁的鏈接最后會多了一個(gè)“/”,故會導(dǎo)致點(diǎn)擊分頁跳轉(zhuǎn)時(shí)會提示找不到頁面
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網(wǎng)安備11010802030151號
購課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動(dòng)學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號
2016-09-12
模板中分頁的地方加上搜索的參數(shù),使用Request::input()方法即可,注意參數(shù)層級!
{{ $students->appends(Request::input())->render() }
2016-09-17
老師 上面 是我問題 的代碼?
2016-09-17
在同一頁面 展示
controller?
public function index(Request $request)
{
? ?if (!empty($request['search'])) {
? ? ? ?$goods = Goods::where('tag', 'like', '%' . $request['search'] . '%')->paginate(10);
? ?} else {
? ? ? ?$goods = Goods::paginate(10);
? ?}
? ?$page_title = "商品列表";
? ?$page_level = $this->page_level;
? ?return view('goods.index', compact('goods','page_title', 'page_level'));
}
index.blade.php
<div class="row">
? ?<div class="col-md-6">
? ? ? ?<div class="box box-primary">
? ? ? ? ? ?<form id="tagsearch" class="form-horizontal" action="{{URL::to('goods')}}" method="get" enctype="multipart/form-data">
? ? ? ? ? ? ? ?<div class="box-header with-border">
? ? ? ? ? ? ? ? ? ?<h3 class="box-title">{{$page_title or "Page Title"}}</h3>
? ? ? ? ? ? ? ? ? ?<input type="hidden" name="_token" value="{{csrf_token()}}">
? ? ? ? ? ? ? ?</div>
? ? ? ? ? ? ? ?<div class="box-body">
? ? ? ? ? ? ? ?</div>
? ? ? ? ? ? ? ?<div class="form-group">
? ? ? ? ? ? ? ? ? ?<label for="name" class="col-sm-3 control-label">標(biāo)簽</label>
? ? ? ? ? ? ? ? ? ?<div class="col-sm-8">
? ? ? ? ? ? ? ? ? ? ? ?<input type="text" class="form-control" id="search" name="search" placeholder="標(biāo)簽" value="">
? ? ? ? ? ? ? ? ? ? ? ?@include('layouts.message.tips',['field'=>'name'])
? ? ? ? ? ? ? ? ? ?</div>
? ? ? ? ? ? ? ?</div>
? ? ? ? ? ? ? ?<div class="box-footer">
? ? ? ? ? ? ? ? ? ?<a class="btn btn-default" href="{{route('goods.index')}}">返回</a>
? ? ? ? ? ? ? ? ? ?<button type="submit" class="btn btn-danger pull-right">搜索</button>
? ? ? ? ? ? ? ?</div>
? ? ? ? ? ?</form>
? ? ? ?</div>
? ?</div>
</div>
<div class="row">
? ?<div class="col-md-12">
? ? ? ?<div class="box">
? ? ? ? ? ?<div class="box-header with-border">
? ? ? ? ? ? ? ?<h3 class="box-title">商品信息列表</h3>
? ? ? ? ? ?</div>
? ? ? ? ? ?<div class="box-body table-responsive no-padding">
? ? ? ? ? ? ? ?<table class="table table-hover">
? ? ? ? ? ? ? ? ? ?<tr>
? ? ? ? ? ? ? ? ? ? ? ?<th>編號</th>
? ? ? ? ? ? ? ? ? ? ? ?<th>商品名稱</th>
? ? ? ? ? ? ? ? ? ? ? ?<th>標(biāo)簽</th>
? ? ? ? ? ? ? ? ? ? ? ?<th>地址</th>
? ? ? ? ? ? ? ? ? ? ? ?<th>價(jià)格</th>
? ? ? ? ? ? ? ? ? ? ? ?<th>發(fā)布時(shí)間</th>
? ? ? ? ? ? ? ? ? ? ? ?<th>管理操作</th>
? ? ? ? ? ? ? ? ? ?</tr>
? ? ? ? ? ? ? ? ? ?@forelse($goods as $goodinfo)
? ? ? ? ? ? ? ? ? ? ? ?<tr>
? ? ? ? ? ? ? ? ? ? ? ? ? ?<td>{{ $goodinfo['id'] }}</td>
? ? ? ? ? ? ? ? ? ? ? ? ? ?<td>{{ $goodinfo['name'] ?}}</td>
? ? ? ? ? ? ? ? ? ? ? ? ? ?<td>{{ $goodinfo['tag'] }}</td>
? ? ? ? ? ? ? ? ? ? ? ? ? ?<td>{{ $goodinfo['region'] }}</td>
? ? ? ? ? ? ? ? ? ? ? ? ? ?<td>{{ $goodinfo['price'] }}</td>
? ? ? ? ? ? ? ? ? ? ? ? ? ?<td>{{ $goodinfo['created_at'] }}</td>
? ? ? ? ? ? ? ? ? ? ? ? ? ?<td>
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?<button class="btn btn-danger" data-toggle="modal" data-target="#defalutModal" data-url="{{URL::to('goods/'.$goodinfo['id'])}}">
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?@if($goodinfo['status']) 下架 @else 上架 @endif
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?</button>
? ? ? ? ? ? ? ? ? ? ? ? ? ?</td>
? ? ? ? ? ? ? ? ? ? ? ?</tr>
? ? ? ? ? ? ? ? ? ?@empty
? ? ? ? ? ? ? ? ? ? ? ?<tr>
? ? ? ? ? ? ? ? ? ? ? ? ? ?<td colspan="9" class="text-center">暫無數(shù)據(jù)</td>
? ? ? ? ? ? ? ? ? ? ? ?</tr>
? ? ? ? ? ? ? ? ? ?@endforelse
? ? ? ? ? ? ? ?</table>
? ? ? ? ? ?</div>
? ? ? ? ? ?@if($goods->render() !== "")
? ? ? ? ? ? ? ?<div >
? ? ? ? ? ? ? ? ? ?{!! $goods->render() !!}
? ? ? ? ? ? ? ?</div>
? ? ? ? ? ?@endif
? ? ? ?</div>
? ?</div>
</div>