如何创建分页来改变laravel中的html

时间:2018-04-10 03:27:11

标签: laravel pagination

 <div class="row clearfix">
            @foreach($distric->area_list as $area_list)

               @foreach($area_list->directory as $directory)
               @foreach($directory->dir_category_sub_set as $dir_category_sub_set)
               @if($dir_category_sub_set->sub_category_id == '557057')

                <div class="col-sm-4 col-xs-6">
                  <div class="single-product">
                    <figure>
                      <img src="/img/content/post-img-12.jpg" alt="">

                      <div class="rating">
                        <ul class="list-inline">
                          <li><a href="#"><i class="fa fa-star"></i></a></li>
                          <li><a href="#"><i class="fa fa-star"></i></a></li>
                          <li><a href="#"><i class="fa fa-star"></i></a></li>
                          <li><a href="#"><i class="fa fa-star-half-o"></i></a></li>
                          <li><a href="#"><i class="fa fa-star-o"></i></a></li>
                        </ul>

                        <p>Featured</p>

                      </div> <!-- end .rating -->

                      <figcaption>
                        <div class="bookmark">
                          <a href="https://hanuma.lk/{{$directory->field_link}}"><i class="fa fa-bookmark-o"></i> Bookmark</a>
                        </div>

                        <div class="read-more">
                          <a href="https://hanuma.lk/{{$directory->field_link}}"><i class="fa fa-angle-right"></i> Read More</a>
                        </div>

                      </figcaption>
                    </figure>

                    <h4><a href="https://hanuma.lk/{{$directory->field_link}}">{{$directory->name_of_the_business_place}}</a></h4>

                    <h5><a href="https://hanuma.lk/{{$directory->field_link}}">{{$directory->address_no_of_the_business_place}},{{$directory->address_street_of_the_business_place}}</a>, <a href="/land/{{$directory->directory_id}}">{{$area_list->name}},{{$distric->name}}</a></h5>

                    <p>T.P:
                      @if($directory->phone_of_the_business_place>0)
                      {{$directory->phone_of_the_business_place}}/
                      @endif

                      {{$directory->mobile_of_the_business_place}} <br> {{$directory->created_date}}</p>

                    <a class="read-more" href="https://hanuma.lk/{{$directory->field_link}}"><i class="fa fa-angle-right"></i>Read More</a>

                  </div> <!-- end .single-product -->
                </div> <!-- end .grid-layout -->
                @endif  
                  @endforeach
                  @endforeach
                  @endforeach

我有这个代码,我想为此创建分页如何做到这一点,我可以这样做,没有任何页面刷新?我不能使用laravel分页方法,因为我不直接从数据库中获取数据

我搜索了不同的方法来添加分页,但我无法为我的项目罚款一个合适的方法

1 个答案:

答案 0 :(得分:0)

Laravel提供了分页方法,您可以使用laravel pagination

您只需要检索数据并添加如下方法:

$documents = District::find($id)->area_list()->directory()->get();
return response()->json($documents);

并在您的视图中显示分页链接,如:

{{$documents->links()}}
@foreach($documents as $document)
    {{$document->name}}
@endforeach

完成,这是如何使用分页的示例。