【问题标题】:NotFoundHTTPException while pagination. Laravel分页时出现 NotFoundHTTPException。拉拉维尔
【发布时间】:2016-10-31 17:16:39
【问题描述】:

我正在尝试对我的观点进行分页。我使用以下语法来做到这一点: 路线:

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() !!}

虽然第一页的分页工作正常,但当我点击下一页时,它会抛出带有 URL 的 not foundhttpexception:

http://localhost:8000/Bill/view/month/custom/url?page=2

我该如何解决这个问题?谁能帮帮我?

【问题讨论】:

    标签: pagination routes laravel-5.2


    【解决方案1】:

    你还需要有一个 GET 路由

    Route::get('Bill/view/month/history/custom/url','BillController@monthHistory');
    

    在您的路线文件中。

    或者您可以这样做

    使用自定义 url 作为路由的可选变量,如下所示。

    Route::get('Bill/view/month/history/{custom?}/{url?}','BillController@monthHistory');
    

    并在您的控制器中使用这样的设置路径

    $bills->setPath('/Bill/view/month/history/custom/url');
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-05-26
      • 2015-10-30
      • 2023-03-29
      • 1970-01-01
      • 2021-08-23
      • 2017-03-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多