我想根据选择框和搜索框中选择的值显示数据。但是选择框(也许搜索框也有相同的问题)每当我点击页面2,3,4 ....
时重置我相信我在视图/控制器中错过了分页代码。
请告诉我解决此问题的方法。
控制器
class MemberListTestController extends Controller
{
public function search(Request $request)
{
$request->flash();
$memberName = $request->input('memberName');
$chosenCenter = $request->input('chosenCenter');
$memberLists= DB::table('tbMbrMember as Member')
->select(['Org.orgNm',
'Member.firstNm',
'Member.lastNm',
'Member.regDate',
'MshipCd.mshipNm',
'Att.dt',
'Member.phoneCell',
'Member.email',
'Group.groupNm',
DB::raw('MAX(Att.dt) AttDt, GREATEST(MAX(Reg.endDt),MAX(Reg.expDt)) rExpDt')])
->join('tbMbrCenter as Center', 'Member.mbrCd', '=', 'Center.mbrCd')
->join('tbCmOrg as Org', 'Center.orgCd', '=', 'Org.orgCd')
->leftjoin('tbMbrGroup as Group','Center.orgCd','=','Group.orgCd')
->leftjoin('tbMbrMshipReg as Reg', 'Member.mbrCd', '=', 'Reg.mbrCd')
->leftjoin('tbCmMshipCd as MshipCd', 'MshipCd.mshipCd', '=', 'Reg.mshipCd')
->leftjoin('tbMbrAtt as Att', 'Att.mbrCd', '=', 'Member.mbrCd')
->where('Center.orgCd', $chosenCenter)
->groupby('Member.mbrCd')
->paginate(25);
$centerLists = DB::table('tbMbrCenter as Center')
->select('Org.orgNm','Center.orgCd')
->join('tbCmOrg as Org', 'Center.orgCd', '=', 'Org.orgCd')
->where('Center.isShow','1')
->where('Org.companyCd','c1')
->where('Org.isShowList','1')
->groupby('Center.orgCd')
->orderby('Org.orgNm')
->get();
return view('member.memberList_test')
-> with('memberLists', $memberLists)
-> with('centerLists', $centerLists);
}
}
路线
Route::group(['middleware' => ['web']], function () {
Route::get('member/test','MemberListTestController@search');
Route::post('member/test','MemberListTestController@search');
});
查看
@extends('layouts.master')
@section('content')
<div class="container-fluid">
<p></p>
<div class="row"></div>
<div class="row">
<div class="col-md-4">
<form method="post" action="{{ url('member/test') }}" enctype="multipart/form-data">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<div class="form-group">
<select class="form-control" id="chosenCenter" name="chosenCenter">
<option value="" selected disabled> Choose Center</option>
@foreach ( $centerLists as $centerList )
<option value= {{ $centerList->orgCd }} @if (old('chosenCenter') == $centerList->orgCd) selected @endif > {{ $centerList->orgNm }}</option>
@endforeach
</select>
</div>
<div class="form-group">
<div class="input-group">
<input type="text" class="form-control"
placeholder="Search for First Name, Last Name... 'search all' for blank "
name="memberName">
<span class="input-group-btn">
<button class="btn btn-default " type="submit">Search</button>
</span>
</div>
</div>
</form>
</div>
</div>
<div class='row'></div>
<div class="row">
<table class="table table-striped table-condensed">
<thead>
<th>#</th>
<th>Center</th>
<th>First Name</th>
<th>Last Name</th>
<th>Date of Reg.</th>
<th>Recent Membership</th>
<th>Date of Membership Exp.</th>
<th>Latest Attendance</th>
<th>Cell Phone</th>
<th>Email</th>
<th>Member Group</th>
</thead>
<tbody>
<?php $count = 1; ?>
@foreach($memberLists as $memberList)
<tr>
<td>{{ (($memberLists->currentPage() - 1 ) * $memberLists->perPage() ) + $count++}}</td>
<td> {{ $memberList->orgNm }}</td>
<td> {{ $memberList->firstNm }} </td>
<td> {{ $memberList->lastNm }} </td>
<td> {{ $memberList->regDate }} </td>
<td> {{ $memberList->mshipNm }}</td>
@if (($memberList->rExpDt) >= date('y-m-d'))
<td> {{$memberList->rExpDt }}</td>
@else
<td> Expired on {{ $memberList->rExpDt }} </td>
@endif
<td>{{ $memberList->AttDt }}</td>
<td> {{ $memberList->phoneCell }}</td>
<td> {{ $memberList->email }}</td>
<td> {{ $memberList->groupNm }} </td>
</tr>
@endforeach
</tbody>
</table>
{!! $memberLists->render() !!}
</div>
</div>
@stop
答案 0 :(得分:1)
您必须通过GET传递参数并从URL恢复参数。
{!! $memberLists->appends(Input::all())->render() !!}
这将发送到第2页,依此类推......包含所有输入值。
答案 1 :(得分:0)
我在laracasts中发现了一个视频,解释了laravel 5.2中刀片模板的所有内置分页选项:
https://laracasts.com/lessons/crazy-simple-pagination
你会发现搜索页面的正确方法是:
{{ $memberLists->appends(Request::except('page'))->links() }}
这样它将保持当前的url参数。