How to receive API LengthAwarePaginator data in Livewire and use it directly
There are cases where Livewire is used for the frontend, with the API endpoints handled separately in the Laravel backend. On the Livewire frontend, you may wan
GGAMI·
There are cases where Livewire is used for the frontend, with the API endpoints handled separately in the Laravel backend.
On the Livewire frontend, you may want to use the API endpoints as they are as much as possible. In that case, you can use this approach.
I wrote about this in that post https://ggami.net/posts/234 before, but that version was for Livewire v2, while the current version is Livewire v3. Quite a lot of time has passed, and there have been many changes.
In the frontend blade.php file, you can write it like this.
However, Livewire v3 introduced some changes, and you need to implement all of these as well.
useWithPagination{ setPage as withPaginationSetPage;}#[Url(as:'p',except:1)]public$page=1;publicarray$filter=['search'=>'','order'=>'id.desc',];publicfunctionsetPage(int$page):void{$this->withPaginationSetPage(page:$page,pageName:'p');$this->page=$page;}
You need to add setPage. (You also need to set this−>page=page...)
But after doing all this, there was a problem with {{ $itemPaginator?->links('vendor.livewire.tailwind') }}.
There was a problem when clicking the PreviousNext buttons.
This is because of $items->forPage(1, $perPage), here: the page must be fixed at 1 for the data to be displayed correctly. (You must not pass in $page.)
As a result, next becomes 2 and previous becomes 1.
To solve this problem, you need to modify the tailwind.blade.php file.