chrisgrim's avatar

Pagination Buttons Not Showing

Hi All,

I have gotten pagination working on other projects, but I am stumped with my latest one. I am using the code

$brands = Brand::latest()->paginate(2);
        return view('brands.index', compact('brands'));

and in the post I can see only 2 brands. If I change the number to 3 then I will see 3 brands. The problem is I can't see the numbers/links at the bottom to switch to the next page.

I looked in my sources for errors and I get these

util.js:56 Uncaught TypeError: Cannot read property 'fn' of undefined
    at util.js:56
    at util.js:10
    at bootstrap.min.js:6
    at bootstrap.min.js:6
(anonymous) @ util.js:56
(anonymous) @ util.js:10
(anonymous) @ bootstrap.min.js:6
(anonymous) @ bootstrap.min.js:6
app.js:13941 CSRF token not found: https://laravel.com/docs/csrf#csrf-x-csrf-token
VERSION @ app.js:13941
__webpack_require__ @ app.js:20
(anonymous) @ app.js:13884
__webpack_require__ @ app.js:20
(anonymous) @ app.js:13869
__webpack_require__ @ app.js:20
(anonymous) @ app.js:63
(anonymous) @ app.js:66
app.js:36537 [Vue warn]: Cannot find element: #app
warn @ app.js:36537
query @ app.js:41244
Vue.$mount @ app.js:46822
Vue._init @ app.js:40584
Vue @ app.js:40673
(anonymous) @ app.js:13896
__webpack_require__ @ app.js:20
(anonymous) @ app.js:13869
__webpack_require__ @ app.js:20
(anonymous) @ app.js:63
(anonymous) @ app.js:66
app.js:44510 You are running Vue in development mode.
Make sure to turn on production mode when deploying for production.
See more tips at https://vuejs.org/guide/deployment.html

I did a search for the property of 'fn' undefined but that seems an issue with jquery. So I used a cdn for the latest bootstrap css and js and Jquery but nothing seems to bring my buttons/links for the pagination

0 likes
9 replies
Tray2's avatar

Did you put the

{{ $brands->links() }}

In the blade file?

Cronix's avatar
Cronix
Best Answer
Level 67

and he never enters any links() function

Sure he does, at about 8:18 just after he creates the pagination.

I've used pagination many times, and it works if you follow the docs, which I linked to.

If your controller is

$brands = Brand::latest()->paginate(2);
return view('brands.index', compact('brands'));

Then {{ $brands->links() }} should work in the brands.index view.

Is that the view you put the pagination links?

jlrdw's avatar

app.js:13941 CSRF token not found:

Are you trying to list data or trying to post some data.

Are you trying to paginate using jQuery.

Can you please show your entire controller code and entire view page.

Cronix's avatar

@jlrdw it has nothing to do with the problem. It will only confuse the issue to discuss it. That problem is because he didn't change any of the default bootstrap stuff, which is trying to get a token from a meta tag that doesn't exist. But it has nothing to do with this pagination problem so let's not confuse this. And no, if you watched the video he is following, it has nothing to do with paginating with jQuery. It's completely unrelated.

chrisgrim's avatar

Cronix you are the best!!! I can't believe I missed that part with him putting in the links! Thank you so much.

Please or to participate in this conversation.