Can I define the sort order of siblings with an order column #199
-
Hi everyone, I would like to use this package to organise the hierarchy of elements with parent_id and an order_column for the siblings. Given the following records :
I would like to order the pages by depth and order_column :
If I get the tree of the records and use the
If I get the tree of the records and use the
Is it possible to use adjacency list with an order column to define the order between siblings instead of this order only being decided by the parent id and the primary key ? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hi @groenewege, class Page extends Model
{
use HasRecursiveRelationships;
public function getCustomPaths()
{
return [
[
'name' => 'order_path',
'column' => 'order_column',
'separator' => '.',
],
];
}
}
Page::tree()->orderBy('order_path')->get(); |
Beta Was this translation helpful? Give feedback.
Hi @groenewege,
Try adding a custom path for
order_column
and using it to order depth-first: