0

In my controller I'm displaying records in a table in my View.

Controller:

$promotion = Promotions::paginate(5);

View:

                            <tr>
                                <th>Order</th>
                                <th>Infomation</th>
                                <th>Date</th>
                                <th>Cost</th>
                                <th>From</th>
                            </tr>
                        </thead>
                        <tbody align="center">
                            <?php $i = 0;?>
                            @foreach ( $promotion as $promo)
                            <?php $i++;?>
                            <tr>
                                <td data-title="Order">{{$i}}</td>
                                <td data-title="Infomation">{{$promo['name']}}</td>
                                <td data-title="Date">29/10/57</td>
                                <td data-title="Cost">1.99$</td>
                                <td data-title="From">K-Bank</td>
                            </tr>
                            @endforeach
                        </tbody>

It works properly when I locate manually to exampleurl/mypage?page=2

All seems well. However, I wanted to create two text buttons to go back and fourth between pages.

How can I set these to navigate the pagination back and fourth:

<a href="">Previous</a>
<a href="">Next</a>

EDIT: I don't understand why I'm getting downvoted for this question. No where can I find a tutorial on how to split the back and fourth buttons. How professional can your website be if you're restricted to placing the page links to one spot on the page? seriously...

Thomas Charlesworth
  • 1,789
  • 5
  • 28
  • 53

1 Answers1

2

In Laravel 5 there is a single configuration option for Eloquent models to generate pagination. So, you can use the method:

<?php echo $promotion->render(); ?>

If you want an option only with Previous and Next buttons, you need to use

$promotion = Promotions::simplePaginate(5);

Instead of

$promotion = Promotions::paginate(5);
  • I understand this. Thanks, but what if I wanted to separate the two back and fourth buttons? Because when you $promotion->render() , it simple puts them together. Is there a way of customizing it the back and fourth links? – Thomas Charlesworth Apr 02 '15 at 08:09
  • In this case you need to use a custom `Presenter` for the pagination. Look at [Custom pagination view in Laravel 5](http://stackoverflow.com/questions/28240777/custom-pagination-view-in-laravel-5/28542607#28542607) or [Custom pagination view](https://laracasts.com/discuss/channels/general-discussion/custom-pagination-view/replies/34679) – Wenceslao Negrete Apr 02 '15 at 08:30