@kazehaya As suggested here you can do something like that:
$items = Item::all();
$tree = [];
foreach($items as $item) {
$pid = $row->parent_id;
$id = $row->id;
$name = $row->name;
// Create or add child information to the parent node
if (isset($tree[$pid]))
// a node for the parent exists
// add another child id to this parent
$tree[$pid]["children"][] = $id;
else
// create the first child to this parent
$tree[$pid] = array("children"=>array($id));
// Create or add name information for current node
if (isset($tree[$id]))
// a node for the id exists:
// set the name of current node
$tree[$id]["name"] = $name;
else
// create the current node and give it a name
$tree[$id] = array( "name"=>$name );
}
// $tree now holds the structure
@kazehaya It depends on how you look at it. Both are solid and tested packages that you can install and be using in minutes.
You might be using 10% of what they offer, but you know it is going to work.
On the other hand you can spend time coding and testing a solution that fits exactly what you need.
Depending on your needs / point of view either could be considered an overkill. If you are focusing on productivity and have a solution as soon as possible, one of those packages might be the best option.
If you are focusing on learning and improving your skills, it might be better to code your own solution.
In my opinion there is no right or wrong answer.