You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Livewire 3中结合分页使用offset偏移失效问题求助

Livewire 3中结合分页使用offset偏移失效问题求助

各位好,我目前在Livewire 3开发文章列表功能时碰到了个棘手的问题:页面上方已经单独展示了4篇最新文章,所以我想让下方的分页列表直接跳过这4篇,从第5篇开始加载。可是我在查询语句里加上->offset(4)之后完全没效果,分页还是从第1篇文章开始算,这是为啥呀?是不是我哪里的写法有问题?

下面是我的组件完整代码:

<?php

namespace App\Livewire\Web\Post;

use Illuminate\Support\Facades\DB;
use Livewire\Attributes\Url;
use Livewire\Component;
use Livewire\WithPagination;

class ArticleIndex extends Component
{
    use WithPagination;

    public $lang;
    public $dataCategories;

    #[Url('c')]
    public $filterCategory = null;

    #[Url('y')]
    public $filterTrending = null;

    public $filterSearch = null;

    public function mount()
    {
        $this->dataCategories = DB::table('taxonomy_terms')
            ->where('taxonomy', 'article_categories')
            ->get();
    }

    public function render()
    {
        $dataArticle = DB::table('entries')
            ->where('collection', 'article')
            ->when($this->filterSearch, function ($query) {
                return $query->whereRaw("LOWER(JSON_UNQUOTE(JSON_EXTRACT(data, '$.title'))) LIKE ?", ['%' . strtolower($this->filterSearch) . '%']);
            })
            ->when($this->filterCategory, function ($query) {
                return $query->whereJsonContains('data->article_categories', \Str::slug($this->filterCategory));
            })
            ->where('site', $this->lang == "en" ? "english" : "indonesia")
            ->orderBy('date', 'desc')
            ->where('published', true)
            ->offset(4)
            ->paginate(5);

        return view('livewire.web.post.article-index', compact('dataArticle'));
    }

    public function search()
    {
        $this->resetPage();
        $this->filterSearch == $this->filterSearch;
    }

    public function updatedFilterCategory()
    {
        $this->resetPage();
    }

    public function updatedFilterYear()
    {
        $this->resetPage();
    }
}

有没有大佬能帮我排查下问题所在呀?

内容来源于stack exchange

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.07 10:57:59