Http/Controllers/Admin/CategoryController.php
public function fetchCategories(CategoryGroup $categoryGroup)
    {
        $isTreeOpened = config('netcore.module-category.tree.opened_by_default', false);
        $suffixHelper = config('netcore.module-category.tree.name_suffix_helper_function', null);
        $language = TransHelper::getLanguage();

        $categories = $categoryGroup->categories()->defaultOrder()->get();

        $categories = $categories->map(function (Category $category) use (
            $isTreeOpened,
            $suffixHelper,
            $language,
            $categoryGroup
        ) {
            // Name.
            $categoryName = trans_model($category, $language, 'name');

            if ($suffixHelper && function_exists($suffixHelper)) {
                $categoryName .= $suffixHelper($category);
            }

            // Icons.
            $icons = [];

            if ($categoryGroup->has_icons) {
                $icons = $category->icons->mapWithKeys(function (CategoryIcon $categoryIcon) {
                    return [$categoryIcon->key => $categoryIcon->icon->url()];
                });
            }

            return [
                'id'           => $category->id,
                'parent'       => $category->parent_id ?: '#',
                'text'         => $categoryName,
                'icon'         => $category->icon,
                'li_attr'      => [],
                'a_attr'       => [],
                'translations' => $category->translations,
                'state'        => [
                    'opened'   => $isTreeOpened,
                    'disabled' => false,
                    'selected' => false,
                ],
                'icons'        => $icons,
            ];
        });

        return $categories;
    }
public function fetchCategories(CategoryGroup $categoryGroup)
    {
        $isTreeOpened = config('netcore.module-category.tree.opened_by_default', false);
        $suffixHelper = config('netcore.module-category.tree.name_suffix_helper_function', null);
        $language = TransHelper::getLanguage();

        $categories = $categoryGroup->categories()->defaultOrder()->get();

        $categories = $categories->map(function (Category $category) use (
            $isTreeOpened,
            $suffixHelper,
            $language,
            $categoryGroup
        ) {
            // Name.
            $categoryName = trans_model($category, $language, 'name');

            if ($suffixHelper && function_exists($suffixHelper)) {
                $categoryName .= $suffixHelper($category);
            }

            // Icons.
            $icons = [];

            if ($categoryGroup->has_icons) {
                $icons = $category->icons->mapWithKeys(function (CategoryIcon $categoryIcon) {
                    return [$categoryIcon->key => $categoryIcon->icon->url()];
                });
            }

            return [
                'id'           => $category->id,
                'parent'       => $category->parent_id ?: '#',
                'text'         => $categoryName,
                'icon'         => $category->icon,
                'li_attr'      => [],
                'a_attr'       => [],
                'translations' => $category->translations,
                'state'        => [
                    'opened'   => $isTreeOpened,
                    'disabled' => false,
                    'selected' => false,
                ],
                'icons'        => $icons,
            ];
        });

        return $categories;
    }
public function fetchCategories ( CategoryGroup $ categoryGroup ) { $ isTreeOpened = config ( 'netcore.module-category.tree.opened_by_default' , false ) ; $ suffixHelper = config ( 'netcore.module-category.tree.name_suffix_helper_function' , null ) ; $ language = TransHelper :: getLanguage ( ) ; $ categories = $ categoryGroup -> categories ( ) -> defaultOrder ( ) -> get ( ) ; $ categories = $ categories -> map ( function ( Category $ category ) use ( $ isTreeOpened , $ suffixHelper , $ language , $ categoryGroup ) { // Name. $ categoryName = trans_model ( $ category , $ language , 'name' ) ; if ( $ suffixHelper && function_exists ( $ suffixHelper ) ) { $ categoryName .= $ suffixHelper ( $ category ) ; } // Icons. $ icons = [ ] ; if ( $ categoryGroup -> has_icons ) { $ icons = $ category -> icons -> mapWithKeys ( function ( CategoryIcon $ categoryIcon ) { return [ $ categoryIcon -> key => $ categoryIcon -> icon -> url ( ) ] ; } ) ; } return [ 'id' => $ category -> id , 'parent' => $ category -> parent_id ? : '#' , 'text' => $ categoryName , 'icon' => $ category -> icon , 'li_attr' => [ ] , 'a_attr' => [ ] , 'translations' => $ category -> translations , 'state' => [ 'opened' => $ isTreeOpened , 'disabled' => false , 'selected' => false , ] , 'icons' => $ icons , ] ; } ) ; return $ categories ; }
Get data for JsTree.

@param CategoryGroup $categoryGroup
@return \Illuminate\Database\Eloquent\Collection
Get data for JsTree .