Laravel分页渲染方法不存在



我正在尝试使无限加载/懒惰加载正常工作是我的代码。

控制器

$categories = Category::with(['products' => function ($query) {
                    $query->where('status', StatusConstant::PT_ACTIVE)->paginate(20);
                    $query->with(['purchased' => function ($query) {
                        $query->where('user_id', $this->user->id);
                    }])->paginate(20);
                }])->get();

查看

@foreach($categories as $category)
    <div id="tabs{{ $category->id }}" class="col s12">
        <div class="contents-tabs">
            @if (isset($category->products))
                <div class="infinite-scroll">
                    @forelse($category->products as $record)
                    <div class="cart-product first">
                        <div class="row">
                            <div class="col s4">
                                <div class="contents">
                                    <img src='{{ asset("/storage/uploads/$record->cover") }}' alt="">
                                </div>
                            </div>
                        </div>
                    </div>
                    @empty
                    <div class="cart-product first">
                        <div class="row">
                            <p class="promo">Null</p>
                        </div>
                    </div>
                    @endforelse
                    {!! $category->products->render() !!}
                </div>
            @endif
        </div>
   </div>
@endforeach

JS

$(function() {
        $('.infinite-scroll').jscroll({
            autoTrigger: true,
            loadingHtml: '<img class="center-block" src="{{ asset('images/loading.gif') }}" alt="Loading..." />',
            padding: 0,
            nextSelector: '.pagination li.active + li a',
            contentSelector: 'div.infinite-scroll',
            callback: function() {
                $('ul.pagination').remove();
            }
        });
    });

错误

[2019-05-08 16:41:37]生产。

,因为该方法确实不存在:(

$categoriesIlluminatePaginationLengthAwarePaginator的对象,因为在链末端的 ->paginate(10)

$query->with(['purchased' => function ($query) {
    $query->where('user_id', $this->user->id);
}])->paginate(10);
   //^ here

$category->productsIlluminateDatabaseEloquentCollection的对象。

您必须在致电render()之前分页 products

在刀片视图中尝试$category->products()->paginate(10)->render()

$categories = Category::with(['products' => function ($query) {
                    $query->where('status', StatusConstant::PT_ACTIVE)->paginate(10);
                                                                      //^
                    $query->with(['purchased' => function ($query) {
                        $query->where('user_id', $this->user->id);
                    }])->paginate(10);
                }])->get();

相关内容

  • 没有找到相关文章

最新更新