我无法显示laravel分页。它给了我一个错误未定义的方法stdClass :: links()我使用了渲染方法但是给了我一个错误未定义的方法stdClass :: render()
这是我的代码
<?php $products = DB::table('products')->where('category_id',$category-> id)->paginate(4); ?>
@foreach($products as $products)
<li class="product-item col-md-3 col-sm-6 col-xs-12">
<div class="product-inner">
<div class="thumb has-second-image">
<a href="#">
@if(empty($products-> medium_product_image))
{{ HTML::image('images/no-image.gif',$products-> product_name) }}
@else
{{ HTML::image($products-> medium_product_image,$products-> product_name) }}
@endif
</a>
</div>
<div class="info">
<h3 class="product-name short"><a href="#">{{ $products-> product_name }}</a></h3>
<span class="price">{{ $products-> product_price }}</span>
<del>{{ $products-> product_old_price }}</del>
</div>
</div>
</li>
@endforeach
<nav class="pagination navigation">
<ul class="page-numbers">
<li>{!! $products-> links() !!}</li>
</ul>
答案 0 :(得分:2)
请将此行@foreach($ products as $ products)改为@foreach($ products as $ product)。我认为错误是由于相同的变量名称
答案 1 :(得分:0)
尝试
{!! $products->render() !!}
而不是
{!! $products-> links() !!}