Skip to content
Advertisement

How to use pagination along with laravel eloquent find method in laravel 5.4

I am trying to implement pagination in laravel and got following error

JavaScript

Here is my controller function

JavaScript

Here is the Tag Model

JavaScript

The Tag and Post model has belongsToMany Relationship so there are many posts under the specific tag and my aim is to iterate all posts under the specific tags descending order of post and also to implement pagination in that page.

Here is the code for showtags view

JavaScript

If anybody know how to do this please respond. Thanks in advance.

Advertisement

Answer

I solve the problem by using a simple trick. My aim was to paginate all posts under the same tags just like you guys can see in StackOverflow.

The modified controller function is

JavaScript

As you guys see that I move the paginate() function from find to load function which I use before for sorting post by descending order.

Now in view instead of using traditional method {!! $tag->links() !!} for making link of pagination

I use {!! $tag->paginate(10) !!}

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement