我试图对我的观点进行分页。我使用以下语法来做到这一点: 路线:
Route::get('Bill/view/month/history','BillController@monthHistory');
控制器:
public function monthHistory(Request $request)
{
$month= $request->month;
$bills=Bill::orderBy('created_at', 'desc')->where('month',$month)->paginate(7);
$bills->setPath('custom/url');
return view('Bill.monthResult',compact('bills'));
}
查看:
<div class="row">
<div class="col-sm-12">
@section ('cotable_panel_title','Bills')
@section ('cotable_panel_body')
<table class="table table-bordered">
<thead>
<tr>
<th>Id</th>
<th>Student</th>
<th>Grade</th>
<th>Month</th>
<th>Date Published</th>
<th>Amount</th>
<th>Paid</th>
<th>Balance</th>
<th>User</th>
</tr>
</thead>
<tbody>
@foreach($bills as $bill)
<tr class="info">
<td>{{$bill->id}}</td>
<td>{{$bill->student->first_name}}</td>
<td>{{$bill->grade->grade_name}}</td>
<td>{{$bill->month}}</td>
<td>{{$bill->date_published}}</td>
<td>{{$bill->amount}}</td>
<td>{{$bill->paid}}</td>
<td>{{$bill->fee_status}}</td>
<td>{{$bill->user}}</td>
</tr>
@endforeach
</tbody>
</table>
@endsection
@include('widgets.panel', array('header'=>true, 'as'=>'cotable'))
</div>
</div>
</div>
{!! $bills->render() !!}
虽然Pagination对于第一页工作正常,但是当我点击下一页时,它会抛出不是findhttpexception的URL:
http://localhost:8000/Bill/view/month/custom/url?page=2
我该如何解决这个问题?任何人都可以帮助我吗?
答案 0 :(得分:0)
您还需要有
的GET路线Route::get('Bill/view/month/history/custom/url','BillController@monthHistory');
在您的路线文件中。
或者你可以这样做
使用自定义网址作为路线上的可选变量,如下所示。
Route::get('Bill/view/month/history/{custom?}/{url?}','BillController@monthHistory');
并在控制器中使用这样的设置路径
$bills->setPath('/Bill/view/month/history/custom/url');