Skip to content

Can I define the sort order of siblings with an order column #199

Answered by staudenmeir
groenewege asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @groenewege,
Try adding a custom path for order_column and using it to order depth-first:

class Page extends Model
{
    use HasRecursiveRelationships;

    public function getCustomPaths()
    {
        return [
            [
                'name' => 'order_path',
                'column' => 'order_column',
                'separator' => '.',
            ],
        ];
    }
}

Page::tree()->orderBy('order_path')->get();

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@groenewege
Comment options

@groenewege
Comment options

@groenewege
Comment options

Answer selected by groenewege
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants