public static function unlimitedForLevel($cate, $html = '--', $pid = 0, $level = 0)
{
$arr = array();
foreach ($cate as $k => $v) {
if ($v['pid'] == $pid) {
$v['level'] = $level + 1;
$v['html'] = str_repeat($html, $level);
$arr[] = $v;
$arr = array_merge($arr, self::unlimitedForLevel($cate, $html, $v['id'], $level + 1));
}
}
return $arr;
}
/** * Show the form for editing the specified resource. * * @param int $id * @return Response */ public function edit($id) { $categories = $this->repository->orderBy('id', 'desc')->paginate(15); $selectedCategory = CategoryService::unlimitedForLevel($categories->toArray()['data']); $category = $this->repository->find($id); return view('backend.news.category_edit', ['category' => $category, 'selectCategory' => $selectedCategory]); }