Laravel Pagination链接()不起作用

时间:2018-01-16 15:24:01

标签: php laravel pagination

在我的控制器中执行此操作后

   $activities = Package::where('attraction',1)
              ->where('hotel', 0)
              ->where('flight', 0)
              ->paginate(2);
          return view('frontend.activities',compact('activities'));

我在此fomrmat

中添加了在我的刀片页面上添加的for
@foreach($activities as $activity)
                    <div class="col-md-3 page-content-1">
                        <div class="thumb">
                            <header class="thumb-header">
                                <a class="hover-img" href="{{url('/flight-details')}}">
                                    <img src="img/new_york_at_an_angle_800x600.jpg" alt="Image Alternative text" title="new york at an angle" />
                                    <h5 class="hover-title-center">Book Now</h5>
                                </a>
                            </header>
                            <div class="thumb-caption">
                                <ul class="icon-group text-tiny text-color">
                                    <li><i class="fa fa-star"></i>
                                    </li>
                                    <li><i class="fa fa-star"></i>
                                    </li>
                                    <li><i class="fa fa-star"></i>
                                    </li>
                                    <li><i class="fa fa-star"></i>
                                    </li>
                                    <li><i class="fa fa-star"></i>
                                    </li>
                                </ul>
                                <h5 class="thumb-title"><a class="text-darken" href="{{url('/flight-details')}}">Manhattan Skyline</a></h5>
                                <p class="mb0"><small><i class="fa fa-map-marker"></i> Queens (LaGuardia Airport (LGA))</small>
                                </p>
                                <p class="mb0 text-darken"><span class="text-lg lh1em text-color"><small >from</small> Free</span>
                                </p>
                            </div>
                        </div>
                    </div>
                    @endforeach

然后我在页面上添加了{{ $activities->links() }}。 每当出现视图时,links()都不会显示页面的链接。 我错过了什么或者有什么我做错了

P.S:我也试过{{$activities->render()}},它也没用。

5 个答案:

答案 0 :(得分:2)

在刀片文件中尝试以下代码:

{!! $activities->render() !!}

代替

{{$activities->render()}}

答案 1 :(得分:1)

在Laravel 5.5中,如果Paginator对象只有一个页面,则不会显示分页链接。

如果您想要显示这些链接,则需要customize the pagination view

1。运行此命令可将分页视图复制到resources/views/vendor/pagination

php artisan vendor:publish --tag=laravel-pagination

2。编辑resources/views/vendor/pagination/default.blade.php

更改第一行:

@if ($paginator->hasPages())

要:

@if ($paginator->count > 0)

答案 2 :(得分:0)

    $items = $user_1->all();

    // Store records in an array
    $records = [];

    $i = 0;
    foreach($items as $item)
    {
        $records[$i][0] = $item->user_name;
        $records[$i][1] = $item->rech_mobile;
        $i++;
    }


    /****above code was replaced by the following code***/
    $items = $user_1->all()->toArray();
       /***---toArray() function used to convert object to array***/

答案 3 :(得分:0)

controller:   $users = DB::table('users')->Paginate(10);
 view file  : {{$users->links('vendor.pagination.default')}}

运行命令:

php artisan vendor:publish --tag=laravel-pagination

答案 4 :(得分:-1)

在“ @endforeach”语句之后添加以下行

{{ $activities->links('pagination::bootstrap-4') }}

如果没有链接,请检查项目中是否包含引导程序版本4 CSS。