activate_parents not works if child id is less than parent's one
Opened this issue · 1 comments
activate_parents not works if child id is less than parent's one
I have traced the problem to file:
\vendor\lavary\laravel-menu\src\Lavary\Menu\Item.php
method:
public function activate(Item $item = null, $recursion = false)
line:
$this->activate($this->builder->whereId($item->parent)->first(), true);
If parent's id is 13 but the child's id 11 this code returns null:
$this->builder->whereId($item->parent)
It has to activate the parent items after all items are being added to the Menu.
My solution was to sort by id DESC before build the menu.
Still this problem occurs because of procedural style of programming and it could be more OOP style.
Thanks for the report. I don't have time to dig into, but sounds like a good issue for a PR if someone wants to take look.