sannjay's avatar

How to use view component for pagination?

I am bit confuse how to use a view component for pagination? I mean my pagination component is called in view file like this

<!--foreach loop to show items card-->

<div id="pagination" class="p-4"> 
      <!--below is pagination code-->   
      <x-pagination></x-pagination>
</div>

And to show pagination we use below code generally in our view.

$products->links();

I am using Tailwind to style my pagination, and I know by default Laravel use Tailwind to generate default pagination. But I want to use mine because I have customized it according to my theme. Any other pro tip?

0 likes
4 replies
vincent15000's avatar
Level 63

To use your own pagination theme, you have just to specify it in the links() method.

{{ $products->links('views.to.my.pagination.theme') }}
sannjay's avatar

@vincent15000 So in my case, I have to pass the pagination component ?

It would be more neat if we have something like

<x-pagination :links="$product->links()"><x-pagination>
1 like
vincent15000's avatar

I don't thinks that it's possible to create a pagination component, because the links() method displays the pagination. So the only way to customize the pagination is to create a simple blade view which you pass as a parameter to the links() method.

Please or to participate in this conversation.