Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

officersiam's avatar

livewire 3 pagination breaks when going back to first page or 3rd or 4th page

when i go to my 2nd page, it perfectly showing all data with pagination, when want to go 3rd page, it shows only 4 data without showing pagination button. or when i want to go back to 1st page, it only shows 1 or 4 data without showing any pagination button.

Livewire ProfileFeed.php page

<?php
namespace App\Livewire;

use App\Models\LawPost;
use App\Models\QBankPost;
use Livewire\Component;
use Livewire\WithPagination;
use Illuminate\Support\Facades\DB;

class ProfileFeed extends Component
{
    use WithPagination;

    protected $paginationTheme = 'tailwind';

    public function getPostsProperty()
    {
        $qbankQuery = QBankPost::query()
            ->where('is_published', true)
            ->select('id', 'question as title', 'slug', 'answer as content', 'published_at', 'seo_image', 'label');

        $lawPosts = LawPost::query()
            ->where('is_published', true)
            ->select('id', 'title', 'slug', 'content', 'published_at', 'seo_image', 'label');

        $combinedQuery = $lawPosts->unionAll($qbankQuery);

        return DB::table(DB::raw("({$combinedQuery->toSql()}) as combined"))
            ->mergeBindings($combinedQuery->getQuery())
            ->orderBy('published_at', 'desc')
            ->paginate(10);
    }

    public function render()
    {
        return view('livewire.profile-feed', [
            'posts' => $this->posts,
        ]);
    }
}

In profile-feed.blade.php livewire view page

<div>
    @forelse ($posts as $post)
        <div wire:key="{{ $post->id }}">
            <article class="group grid rounded-sm grid-cols-1 md:grid-cols-8 overflow-hidden border border-neutral-300 bg-neutral-50 text-neutral-600 dark:border-neutral-700 dark:bg-neutral-900 dark:text-neutral-300 mb-5">
                <div class="flex items-center justify-center overflow-hidden mx-5 my-5">
                    <img src="{{ $post->seo_image ? asset($post->seo_image) : asset('images/' . $post->label . '/' . $post->slug . '.jpg') }}" class="h-52 md:h-full w-full object-cover transition duration-700 ease-out group-hover:scale-105" alt="{{  $post->title }}" />
                </div>
                <div class="flex flex-col justify-center p-6 col-span-5">

                    <a href="{{ route("{$post->label}.show", $post->slug) }}">
                        <h3 class="text-balance text-xl font-bold text-neutral-900 lg:text-2xl dark:text-white">{{ $post->title }}</h3>
                        <p class="my-4 max-w-lg text-pretty text-sm">
                            {!! Str::limit($post->content, 150) !!}
                        </p>
                        <span class="w-fit font-medium text-black underline-offset-2 hover:underline focus:underline focus:outline-hidden dark:text-white">
                            Published on: {{ \Carbon\Carbon::parse($post->published_at)->diffForHumans() }}
                        </span>
                    </a>
                </div>
            </article>
        </div>
            @empty
             No Post Found
        @endforelse

    <!-- Livewire pagination links -->
    <div class="mt-6">
        {{ $posts->links() }}
    </div>
</div>

in profile.blade.php view page

<livewire:profile-post-tab />
0 likes
0 replies

Please or to participate in this conversation.