src/Processor/Role.php
public function tree($id)
    {
        $eloquent  = $this->model->findOrFail($id);
        $instances = app('antares.acl')->all();
        $return    = [
            'name'    => 'Root',
            'open'    => true,
            'checked' => false,
        ];
        $modules   = app(ModulesAdapter::class)->modules();
        foreach ($modules as $module) {
            $item        = [
                'saveName'      => array_get($module, 'full_name', '---'),
                'name'          => array_get($module, 'full_name', '---'),
                'indeterminate' => false,
                'checked'       => false,
                'open'          => true,
            ];
            if (!is_null($description = array_get($module, 'description'))) {
                array_set($item, 'description', $description);
            }
            $actions = array_get($module, 'actions', []);
            if (empty($actions) or ! isset($instances[$module['namespace']])) {
                continue;
            }
            $children = [];
            $checked  = true;
            $keys     = array_keys($actions);

            $actionsWithoutCategories = Action::query()->whereIn('id', $keys)->whereNull('category_id')->get();

            foreach ($actionsWithoutCategories as $action) {
                $checked    = $instances[$module['namespace']]->check($eloquent->name, $action->name);
                $key        = array_search($action->name, $actions);
                $children[] = [
                    'saveName'      => "acl[{$id}][{$key}]",
                    'name'          => Str::humanize($action->name),
                    'indeterminate' => false,
                    'checked'       => $checked,
                    'value'         => $action->name,
                    'description'   => $action->description
                ];
                if (!$checked) {
                    $checked = false;
                }
            }
            $actionsWithCategories = \Antares\Model\ActionCategories::query()->with(['actions' => function($query) use($keys) {
                            $query->whereIn('id', $keys);
                        }])->get();

            foreach ($actionsWithCategories as $category) {
                if ($category->actions->isEmpty()) {
                    continue;
                }
                $subchildren = [];
                foreach ($category->actions as $action) {
                    $checked       = $instances[$module['namespace']]->check($eloquent->name, $action->name);
                    $key           = array_search($action->name, $actions);
                    $subchildren[] = [
                        'saveName'      => "acl[{$id}][{$key}]",
                        'name'          => Str::humanize($action->name),
                        'indeterminate' => false,
                        'checked'       => $checked,
                        'value'         => $action->name,
                        'description'   => $action->description
                    ];
                }
                $children[] = [
                    'name'          => $category->name,
                    'saveName'      => "acl_category_" . $category->id,
                    'indeterminate' => false,
                    'checked'       => true,
                    'children'      => $subchildren,
                    'open'          => true
                ];
            }

            $item['checked'] = $checked;

            $item['children']     = $children;
            $return['children'][] = $item;
        }
        return new JsonResponse(['tree' => $return]);
    }
public function tree($id)
    {
        $eloquent  = $this->model->findOrFail($id);
        $instances = app('antares.acl')->all();
        $return    = [
            'name'    => 'Root',
            'open'    => true,
            'checked' => false,
        ];
        $modules   = app(ModulesAdapter::class)->modules();
        foreach ($modules as $module) {
            $item        = [
                'saveName'      => array_get($module, 'full_name', '---'),
                'name'          => array_get($module, 'full_name', '---'),
                'indeterminate' => false,
                'checked'       => false,
                'open'          => true,
            ];
            if (!is_null($description = array_get($module, 'description'))) {
                array_set($item, 'description', $description);
            }
            $actions = array_get($module, 'actions', []);
            if (empty($actions) or ! isset($instances[$module['namespace']])) {
                continue;
            }
            $children = [];
            $checked  = true;
            $keys     = array_keys($actions);

            $actionsWithoutCategories = Action::query()->whereIn('id', $keys)->whereNull('category_id')->get();

            foreach ($actionsWithoutCategories as $action) {
                $checked    = $instances[$module['namespace']]->check($eloquent->name, $action->name);
                $key        = array_search($action->name, $actions);
                $children[] = [
                    'saveName'      => "acl[{$id}][{$key}]",
                    'name'          => Str::humanize($action->name),
                    'indeterminate' => false,
                    'checked'       => $checked,
                    'value'         => $action->name,
                    'description'   => $action->description
                ];
                if (!$checked) {
                    $checked = false;
                }
            }
            $actionsWithCategories = \Antares\Model\ActionCategories::query()->with(['actions' => function($query) use($keys) {
                            $query->whereIn('id', $keys);
                        }])->get();

            foreach ($actionsWithCategories as $category) {
                if ($category->actions->isEmpty()) {
                    continue;
                }
                $subchildren = [];
                foreach ($category->actions as $action) {
                    $checked       = $instances[$module['namespace']]->check($eloquent->name, $action->name);
                    $key           = array_search($action->name, $actions);
                    $subchildren[] = [
                        'saveName'      => "acl[{$id}][{$key}]",
                        'name'          => Str::humanize($action->name),
                        'indeterminate' => false,
                        'checked'       => $checked,
                        'value'         => $action->name,
                        'description'   => $action->description
                    ];
                }
                $children[] = [
                    'name'          => $category->name,
                    'saveName'      => "acl_category_" . $category->id,
                    'indeterminate' => false,
                    'checked'       => true,
                    'children'      => $subchildren,
                    'open'          => true
                ];
            }

            $item['checked'] = $checked;

            $item['children']     = $children;
            $return['children'][] = $item;
        }
        return new JsonResponse(['tree' => $return]);
    }
Modules structure as tree

@param $id
@return \Illuminate\Http\JsonResponse