bryan1671's avatar

Pagination Links not working in view

I've tried everything and cannot get my laravel pagination LINKS to work. When i view the page source, all links are there, and in page source, they work when i click on them. In blade view, clicking the link does nothing. The links buttons are at the bottom of the page in view. In view, I can type in the address bar user?page=2, etc., and it works. The href links in page source show http://127.0.0.1/user?page=2, etc. My debugger shows the correct link when i click the button in view. .htaccess is correct according to installation instructions. HELP!!! Very simple controller to view with no eloquent or model. ?????

0 likes
13 replies
bryan1671's avatar

Here is the page source.

  • «
  •     <!-- Pagination Elements -->
                    <!-- "Three Dots" Separator -->
            
            <!-- Array Of Links -->
                                                                        <li class="page-item active"><span class="page-link">1</span></li>
                                                                                <li class="page-item"><a class="page-link" href="http://127.0.0.1:8000/user?page=2">2</a></li>
                                                                                <li class="page-item"><a class="page-link" href="http://127.0.0.1:8000/user?page=3">3</a></li>
                                                                                <li class="page-item"><a class="page-link" href="http://127.0.0.1:8000/user?page=4">4</a></li>
                                                                                <li class="page-item"><a class="page-link" href="http://127.0.0.1:8000/user?page=5">5</a></li>
                                                        
        <!-- Next Page Link -->
                    <li class="page-item"><a class="page-link" href="http://127.0.0.1:8000/user?page=2" rel="next">&raquo;</a></li>
            </ul>
    
slev1n's avatar

In blade view, clicking the link does nothing

Does nothing = page reloads with the same data inside, page does not reloads at all, always loading specific data set (ie for ?page=1)?

Show your controller method code

jlrdw's avatar

Do you have query string parameters you're not passing.

steve_laracasts's avatar

In your description the url does not have a port declaration, in the code port 8000 is included in all the links - is there a mismatch between your environment and config?

afrasiyabhaider's avatar

@bryan1671 Laravel has a built-in method to create pagination use the following code in your controller while getting data from DB

$posts = Post::orderBy('created_at','desc')->paginate(5 ); return view('posts.index')->with('posts',$posts);

use function : paginate('number_of_posts_per_page');

use the following code in your view

{{$posts->links()}}

Change the data according to your context

Hope it works well

Snapey's avatar

as @kel_ says, pay attention to the port number appended to all your links

bryan1671's avatar

Page does not reload. Clicking the link does nothing. dd($users); shows the correct amount of records. Basic controller. $users = DB::table(users)->paginate(5); the page loads correctly. I can type /users?page=2 in the address bar and it works. The links buttons are not.

bryan1671's avatar

Thats my local server address. Production still does not work. Like I said, page loads correctly and records are correct, just {{ $users-> links }} is not working, but shows on blade.view

jlrdw's avatar

Should be

{{ $users->links() }}

Edit: No space after "->"

bryan1671's avatar

Yes, and it shows the buttons just fine, however, when I click page 2, nothing happens. When I view the page source, all links are correct.

Snapey's avatar

consider the port number, as suggested

slev1n's avatar

Page does not reload. Clicking the link does nothing.

I can type /users?page=2 in the address bar and it works. The links buttons are not.

Then you need to seek problem in javascript, i guess.

In some of your custom script may be statement like

$(document).on('click', '.page-link', function(event) {
    event.preventDefault();

    // do something
}

or similar..

You can inspect element (any of pagination links) for js listeners on click event, find and refactor problem code.

You can google - how to find and debug event listener {your_browser}, it's may help.

bryan1671's avatar
bryan1671
OP
Best Answer
Level 4

Problem solved. I had a modal on my blade file that had a page-link class that was conflicting with the paginate page-link class. i changed the modal class name and the page links work as they should. Thanks for all suggestions.

1 like

Please or to participate in this conversation.