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

[Proposal] Add isFirst() and isLast() #143

Open
ivanBell199 opened this issue Nov 6, 2023 · 0 comments
Open

[Proposal] Add isFirst() and isLast() #143

ivanBell199 opened this issue Nov 6, 2023 · 0 comments

Comments

@ivanBell199
Copy link

Thank you for this great package. I have just started using it and it is very enjoyable. Unless I overlooked, it seems there are no methods to check if a node is first/last within its level. I think it would be useful for something like disabling "up" and "down" buttons when reordering is needed. In my project I simply adjusted methods up() and down():

    /**
     * Check if node is first among siblings.
     *
     * @return bool
     */
    public function isFirst()
    {
        $sibling = $this->prevSiblings()
            ->defaultOrder('desc')
            ->first();

        return $sibling ? false : true;
    }

    /**
     * Check if node is last among siblings.
     *
     * @return bool
     */
    public function isLast()
    {
        $sibling = $this->nextSiblings()
            ->defaultOrder()
            ->first();

            return $sibling ? false : true;
    }

Do you think it is worth being added to the package?

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

No branches or pull requests

1 participant