Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] 希望给 Hyperf\Database\Query\Builder 类增加 forPageBeforeId 方法 #2392

Closed
czy1121 opened this issue Aug 31, 2020 · 3 comments · Fixed by #2411
Closed

[FEATURE] 希望给 Hyperf\Database\Query\Builder 类增加 forPageBeforeId 方法 #2392

czy1121 opened this issue Aug 31, 2020 · 3 comments · Fixed by #2411
Assignees
Labels
enhancement New feature or request

Comments

@czy1121
Copy link

czy1121 commented Aug 31, 2020

Is your feature request related to a problem? Please describe.
forPageAfterId 只适用于正序列序列表分页

Describe the solution you'd like
希望提供 forPageBeforeId 支持倒序列表分页
自增ID越大的越新排在越前边

@czy1121 czy1121 added the enhancement New feature or request label Aug 31, 2020
@limingxinleo
Copy link
Member

这个加个 order 不就行了么?

有没有例子。。

@czy1121
Copy link
Author

czy1121 commented Aug 31, 2020

除了order还有一个比较ID大小的查询条件

public function forPageBeforeId($perPage = 15, $lastId = 0, $column = 'id')
    {
        $this->orders = $this->removeExistingOrdersFor($column);

        if (! is_null($lastId)) {
            $this->where($column, '<', $lastId);
        }

        return $this->orderBy($column, 'desc')
                    ->limit($perPage);
    }

    public function forPageAfterId($perPage = 15, $lastId = 0, $column = 'id')
    {
        $this->orders = $this->removeExistingOrdersFor($column);

        if (! is_null($lastId)) {
            $this->where($column, '>', $lastId);
        }

        return $this->orderBy($column, 'asc')
                    ->limit($perPage);
    }

@limingxinleo
Copy link
Member

可以的,我抽空加一下

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants