Good day. Started learning Laravel. There was a problem with the page output.

There is a controller:

IndexController

Implemented paginated news output:

output news

The problem is that when you go to the second page, information from the banner, interesting news, the block about me disappears.

First page: first page

Second page: last page

Explain to the newcomer what is wrong and where the information will go.

  • how much banner do you have? - Zohid
  • The only one - Andrei Kononov

1 answer 1

It's simple, if you look at the paginate method, you will see that the third parameter is responsible for the name of the parameter in which the page number will be transmitted, the default is page .

In your case, it turns out that all paginators take the value of the page from this parameter, and if you switch the page somewhere, it changes on all paginators. That they do not depend on each other, change the third parameter, for example:

 $banners = Banners::paginate(1, ['*'], 'banners-page'); 

Now, banners will not depend on other paginators, and you need to do this with everyone, but if you honestly don’t understand why you use the paginate method everywhere, you don’t need it, use one , all , get .

  • one
    Thanks for the answer. The second time helping out. - Andrei Kononov
  • @AndreyCononov, yes, it did so :) And for the future, if you don’t need pagination - don’t use it, there are many variations of data output in Larawell. - Yaroslav Molchan