【问题标题】:pagination next button not working on laravel分页下一个按钮在 laravel 上不起作用
【发布时间】:2021-12-14 06:01:37
【问题描述】:

我做错了什么?分页不起作用,我没有收到任何错误。下一个按钮不起作用。有解决办法吗?

class PostsIndex extends Component


    public function render()
    {
        $statuses = Status::all()->pluck('id', 'name');
        $schools = School::all();

        return view('livewire.posts-index', [
            'posts' => Post::with('user', 'school', 'status')
            ->when($this->status && $this->status !== 'All', function ($query) use ($statuses) {
                return $query->where('status_id', $statuses->get($this->status));
            })->when($this->school && $this->school !== 'All Schools', function ($query) use ($schools) {
                return $query->where('school_id', $schools->pluck('id', 'name')->get($this->school));
            })->when($this->filter && $this->filter === 'Top Exp', function ($query) {
                return $query->orderByDesc('votes_count');
            })->when($this->filter && $this->filter === 'My Exp', function ($query) {
                return $query->where('user_id', auth()->id());
            })->when($this->filter && $this->filter === 'Spam Posts', function ($query) {
                return $query->where('spam_reports', '>', 0)->orderByDesc('spam_reports');

            })->when(strlen($this->search) >= 3, function ($query) {
                return $query->where('body', 'like', '%'.$this->search.'%');
            })
                ->addSelect(['voted_by_user' => Vote::select('id')
                    ->where('user_id', auth()->id())
                    ->whereColumn('post_id', 'posts.id')
                ])
                ->withCount('votes')
                ->withCount('comments')
                ->orderBy('id', 'desc')
                ->simplePaginate(10)
                ->withQueryString(),
                'schools' => $schools,
        ]);
    }
}

我已经尽力了,但无法让它工作

【问题讨论】:

  • 您忘记添加参数public function render(Request $request)
  • 这是一个火线组件

标签: php laravel laravel-8


【解决方案1】:

尝试在帖子索引文件中添加链接 {{ $schools->links() }}

【讨论】:

  • 欢迎来到 SO! ? 您能否添加一些正确的代码格式,并可能添加语法高亮?您可以阅读更多关于正确的代码格式和语法突出显示here
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-05-26
  • 2013-01-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多