H
H
HeartOfProgrammer2016-03-22 22:13:17
Laravel
HeartOfProgrammer, 2016-03-22 22:13:17

Why is laravel not creating pagination?

I tried to create pagination on a separate site according to the official article on laravel.com, and I succeeded. I tried to do the same on my site, it did not work.
I have a Product model with the following parameters:

class Product extends Model
{
    protected $table = 'products';
    protected $fillable = [
        'title',
        'description',
        'full_description',
        'author'

    ];
}

My router:
Route::get('/', function(){
    $products = App\Product::paginate(10);
    return View::make('index')->with('products', $products);
});

My view:
<div class="container-fluid">
            <div class="row">
                @foreach( $products as $product )
                <div class="col s12 m6 l4">
                    <div class="card">
                        <div class="card-image">
                            <img src="img/item-img-5.png" alt="">
                            <div class="card-title amber-text darken-2-text ">{!! Html::linkRoute('product.show', $product->title, array($product->id)) !!}</div>
                        </div>
                        <div class="card-content">
                            <p>{{ $product->description }}</p>
                        </div>
                        <div class="card-action amber-text darken-2-text">
                            {!! Html::linkRoute('product.edit', 'Редактировать', array($product->id)) !!}
                            {!! Form::open(['route' => ['product.destroy', $product->id], 'method' => 'delete']) !!}
                            <input type="submit" value="Удалить" />
                            {!! Form::close() !!}
                            <div class="pull-right"><em>{{'Опубликовал - ' . $product->author }}</em></div>
                        </div>
                    </div>
                </div>
                @endforeach
            </div>
    </div>
{!! $products->render() !!}

The entire product from the database is displayed on the site, but there is no pagination, not at all.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrzej Wielski, 2016-03-22
@HeartOfProgrammer

Let me clarify a little: are you sure that you have more than 10 products in your database?

D
Dmitry Kuznetsov, 2016-03-22
@dima9595

If you are using Laravel 4 then instead of

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

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question