sujit
sujit

Reputation: 33

laravel-5.2 pagination not working - undefined method stdClass::links() error

I am not able to display laravel pagination. it gives me an error undefined method stdClass::links() I have used render method but yet gives me an error undefined method stdClass::render()

here is my code

<?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>

Upvotes: 3

Views: 1075

Answers (2)

Bishnu Bhusal
Bishnu Bhusal

Reputation: 1098

Please change this line @foreach($products as $products) to something like @foreach($products as $product) . I think error is Due to same variable name

Upvotes: 3

Drone
Drone

Reputation: 1134

Try with

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

Instead of

 {!! $products-> links() !!}

Upvotes: 0

Related Questions