2
votes

I created my Laravel application with version 5.7 and I also have a Laravel tenancy setup. Here is my controller:

public function index()
    {
        $admins = SystemAdmin::latest()->paginate(1);
        return view('my.admin.settings.admins.index', compact('admins'));
    }

and my code on the view where the pagination links are (blade):

<div class="row">
          <div class="col">
                    <div class="pagination center">
                           {{ $admins->links() }}
                    </div>
           </div>
 </div>

The pagination shows but when I click the links it redirects to the page with the URL bar showing ?page=2 or 3 whatever I clicked, but the 1 value stays highlighted as "active" and the lastest() value, as I called, is the only one that shows since I am only paginating 1 at a time.

UPDATE:::::

I dd() the {{ $admins->links() }} and this is what I get:

HtmlString {#368 ▼
  #html: """
    <ul class="pagination" role="navigation">

                        <li class="page-item disabled" aria-disabled="true" aria-label="&laquo; Previous">
                    <span class="page-link" aria-hidden="true">&lsaquo;</span>
                </li>





                                                                            <li class="page-item active" aria-current="page"><span class="page-link">1</span></li>
                                                                                    <li class="page-item"><a class="page-link" href="https://my.distincttrack.com/ad ▶
                                                                                    <li class="page-item"><a class="page-link" href="https://my.distincttrack.com/ad ▶
                                                                                    <li class="page-item"><a class="page-link" href="https://my.distincttrack.com/ad ▶


                        <li class="page-item">
                    <a class="page-link" href="https://my.distincttrack.com/admin/settings/admins?page=2" rel="next" aria-label="Next &raquo;">&rsaquo;</a>
                </li>
                </ul>
    """
}
3
could you please dd($admins->links()) in index method for two different pages?Ahmed Nour Jamal El-Din
I will try that when I am back to that project later.user7995285

3 Answers

1
votes

Maybe it's because of latest() methods , it always return last .

Use This:

$admins = SystemAdmin::orderBy('created_at','desc')->paginate(1);
0
votes

Does this help?

    $admins = SystemAdmin::latest()->paginate(1);
    return view('my.admin.settings.admins.index')->with('admins', $admins');
0
votes

Check if you are getting query string parameter in your controller:

$request->query('page');

If you are not, it might be due to nginx (or apache) that was removing query string parameter from url. default.conf for nginx can contain:

location / {
    try_files $uri $uri/ /index.php$is_args$args;
}