菜单 学习猿地 - LMONKEY

VIP

开通学习猿地VIP

尊享10项VIP特权 持续新增

知识通关挑战

打卡带练!告别无效练习

接私单赚外块

VIP优先接,累计金额超百万

学习猿地私房课免费学

大厂实战课仅对VIP开放

你的一对一导师

每月可免费咨询大牛30次

领取更多软件工程师实用特权

入驻
3004
0

Laravel Pagination render method does not exist

原创
05/13 14:22
阅读数 2957

一个朋友的问题,感觉这是一个比较有趣的问题,本人才疏学浅,这种写法是否正确,之前也经过查阅资料没有找到合适的方法,期待大佬批评指正。

Controller

$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();

View

@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();
            }
        });
    });

Error

production.ERROR: Method Illuminate\Database\Eloquent\Collection::render does not exist.

原文链接:https://stackoverflow.com/questions/560367...

发表评论

0/200
3004 点赞
0 评论
收藏
为你推荐 换一批