App\Http\Controllers\MenusController::menusOrmToJsTreeJson PHP Метод

menusOrmToJsTreeJson() приватный Метод

private menusOrmToJsTreeJson ( Illuminate\Database\Eloquent\Collection $menusCol ) : string
$menusCol Illuminate\Database\Eloquent\Collection
Результат string
    private function menusOrmToJsTreeJson(Collection $menusCol)
    {
        $jsTreeCol = $menusCol->map(function ($item, $key) {
            $id = $item->id;
            $parent_id = $item->parent_id;
            $label = $item->label;
            $icon = $item->icon;
            // Fix attribute of root item for JSTree
            if ($id == $parent_id && 'Root' == $label) {
                $parent_id = '#';
            }
            return collect(['id' => $id, 'parent' => $parent_id, 'text' => $label, 'icon' => $icon]);
        });
        $menusJson = $jsTreeCol->toJson();
        return $menusJson;
    }