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
相关产品推荐
相关产品推荐

