我的laravel分页有问题

时间:2018-11-16 10:04:01

标签: laravel pagination

我是Laravel的新手。我正在尝试使用引导表中的数据创建分页。

这是我的索引控制器功能:

last_status

我收到此错误:

  

调用未定义的方法App \ Courses :: links()(查看:   C:\ laragon \ www \ TharakaCollege \ resources \ views \ Courses \ index.blade.php)

5 个答案:

答案 0 :(得分:0)

提供的信息还不够,但是我认为问题出在您看来。您的刀片文件中必须有这样的代码:

                <div class="pages">
                    <ul class="pagination ">
                        <li>{{$Courses->appends(request()->query())->links()}}</li>
                    </ul>
                </div>

此外,您最好像这样编辑返回的视图:

return view('Courses.index', array('Courses'=> $Courses));

答案 1 :(得分:0)

这是Courses / index.blade.php中的代码

<div id="page-wrapper">
    @include('includes.message');
    <div class="container-fluid">
        <div class="row">
            <div class="col-lg-12">
                <div class="row">
                    <div class="col-lg-12">
                        <div class="panel panel-info">
                            <div class="panel-heading">
                                Courses
                            </div>
                            <!-- /.panel-heading -->
                            <div class="panel-body">
                                    <div class="table-responsive">
                                <table width="100%" class="table table-striped table-bordered table-hover" id="dataTables-example">
                                    <thead>
                                        <tr>
                                                <th class="text-center">#</th>
                                                <th class="text-center"> code</th>
                                                <th class="text-center">Course Name</th>
                                                <th class="text-center">Category</th>
                                                <th class="text-center">Requirements</th>

                                            </tr>
                                        </thead>
                                        <tbody>
                                            @if(count($Courses)>0)
                                       @foreach($Courses as $Courses)
                                        <tr class="item{{$Courses->id}}">
                                            <td>{{$Courses->id}}</td>
                                            <td>{{$Courses->code}}</td>
                                            <td>{{$Courses->name}}</td>
                                            <td>{{$Courses->category}}</td>
                                            <td>{{$Courses->requirements}}</td>
                                            <td><a class="btn btn-info btn-sm" href="/Courses/{{$Courses->id}}/edit">Edit</a>
                                            </td>
                                            <td>
                                                    <form method="POST" action="{{route('Courses.destroy',$Courses->id)}}">
                                                            <input type="hidden" name="_token" value="{{ csrf_token() }}">
                                                            <input type="hidden" name="_method" value="DELETE">
                                                            <input type="submit" class="btn btn-danger btn-sm" value="Delete">
                                                          </form>
                                            </td>

                                        </tr>
                                        @endforeach
                                        @else
                                        <p>No Courses</p>
                                        @endif
                                        </tbody>
                                    </table>
                                    {{ $Courses->links() }}
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

答案 2 :(得分:0)

调用paginate方法时,您将收到Illuminate\Pagination\LengthAwarePaginator的实例。除了这些辅助方法之外,paginator实例是迭代器,并且可以作为数组循环。因此,一旦检索到结果,就可以显示结果并使用Blade呈现页面链接:

您的刀片应包含:

<div class="container">
    @foreach ($courses as $course)
        {{ $course->fieldName }}
    @endforeach
</div>

{{ $courses->links() }}

答案 3 :(得分:0)

您应该尝试以下操作:

<div class="pull-left">
        <div class="row">
          <div class="col-xs-12">
            <div class="explore-pagination">
              <nav>
                <div class="pagination"> {{ $Courses->render() }}</div>
              </nav>
            </div>
          </div>
        </div>   
      </div>

答案 4 :(得分:0)

改为尝试以下代码(您的代码的修改版本):

<div id="page-wrapper">
@include('includes.message');
<div class="container-fluid">
    <div class="row">
        <div class="col-lg-12">
            <div class="row">
                <div class="col-lg-12">
                    <div class="panel panel-info">
                        <div class="panel-heading">
                            Courses
                        </div>
                        <!-- /.panel-heading -->
                        <div class="panel-body">
                                <div class="table-responsive">
                            <table width="100%" class="table table-striped table-bordered table-hover" id="dataTables-example">
                                <thead>
                                    <tr>
                                            <th class="text-center">#</th>
                                            <th class="text-center"> code</th>
                                            <th class="text-center">Course Name</th>
                                            <th class="text-center">Category</th>
                                            <th class="text-center">Requirements</th>

                                        </tr>
                                    </thead>
                                    <tbody>
                                        @if(count($Courses)>0)
                                   @foreach($Courses as $Course)
                                    <tr class="item{{$Course->id}}">
                                        <td>{{$Course->id}}</td>
                                        <td>{{$Course->code}}</td>
                                        <td>{{$Course->name}}</td>
                                        <td>{{$Course->category}}</td>
                                        <td>{{$Course->requirements}}</td>
                                        <td><a class="btn btn-info btn-sm" href="/Courses/{{$Course->id}}/edit">Edit</a>
                                        </td>
                                        <td>
                                                <form method="POST" action="{{route('Courses.destroy',$Course->id)}}">
                                                        <input type="hidden" name="_token" value="{{ csrf_token() }}">
                                                        <input type="hidden" name="_method" value="DELETE">
                                                        <input type="submit" class="btn btn-danger btn-sm" value="Delete">
                                                      </form>
                                        </td>

                                    </tr>
                                    @endforeach
                                    @else
                                    <p>No Courses</p>
                                    @endif
                                    </tbody>
                                </table>
                                {{$Courses->appends(request()->query())->links()}}
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

我修改了您的foreach循环以及-> links()。