diff --git a/app/Http/Controllers/DivisiController.php b/app/Http/Controllers/DivisiController.php index 06a533c..ea7c3d4 100644 --- a/app/Http/Controllers/DivisiController.php +++ b/app/Http/Controllers/DivisiController.php @@ -9,7 +9,8 @@ class DivisiController extends Controller { private function getAllChildren($divisi, $depth = 0, $array = []) { - $array[$divisi->id] = $divisi->name; + $divisi->depth = $depth; + array_push($array, $divisi); foreach($divisi->children as $child){ $array = $this->getAllChildren($child, $depth + 1, $array); } @@ -69,20 +70,10 @@ class DivisiController extends Controller return response()->json(['status'=>'success','message'=> 'Data deleted!','code'=> 200], 200); } - public function search(Request $request) + public function search() { - $payload = $request->all(); - - if($payload['columns'][0]['value'] == "") - $this->list(); - - $dataBuilder = $this->setUpPayload($payload, 'm_divisi'); - $builder = $dataBuilder['builder']; - $countBuilder = $dataBuilder['count']; - $dataGet = $builder->get(); - $totalRecord = $countBuilder->count(); - - return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); + return $this->list(); + // cant use builder for this case } public function list() @@ -91,7 +82,13 @@ class DivisiController extends Controller $divisions = []; foreach($parentMenus as $menu){ $childs = $this->getAllChildren($menu); - $divisions = $divisions + $childs; + foreach($childs as $d){ + $d->displayName = ' ' . $d->name; + for($i=0; $i < $d->depth; $i++){ + $d->displayName = '--' . $d->displayName ; + } + array_push($divisions, $d); + } } $countData = count($divisions); if($countData == 0)