43 lines
820 B
PHP
Executable File
43 lines
820 B
PHP
Executable File
<?php
|
|
|
|
|
|
namespace App\Logic\Traits;
|
|
|
|
trait MenuTrait
|
|
{
|
|
public function getMenuTree(array $menus)
|
|
{
|
|
$data = [];
|
|
foreach ($menus as $menu) {
|
|
if ($menu['pid'] === 0) {
|
|
$data[] = $this->getChildren($menus, $menu);
|
|
}
|
|
}
|
|
|
|
return $data;
|
|
}
|
|
|
|
public function getChildren($menus, $menu)
|
|
{
|
|
$c = [];
|
|
foreach ($menus as $children) {
|
|
if ($menu['id'] === $children['pid']) {
|
|
$c[] = $this->getChildren($menus, $children);
|
|
}
|
|
}
|
|
$menu['children'] = $c;
|
|
$menu['api'] = $this->formatApi($menu['api']);
|
|
|
|
return $menu;
|
|
}
|
|
|
|
public function formatApi($api)
|
|
{
|
|
if ($api) {
|
|
return explode(';', $api);
|
|
}
|
|
|
|
return [];
|
|
}
|
|
}
|