|
|
@ -8,7 +8,8 @@ use App\Models\Divisi; |
|
|
|
class DivisiController extends Controller |
|
|
|
class DivisiController extends Controller |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
private function getAllChildren($divisi, $depth = 0, $array = []) { |
|
|
|
private function getAllChildren($divisi, $depth = 0, $array = []) |
|
|
|
|
|
|
|
{ |
|
|
|
$divisi->depth = $depth; |
|
|
|
$divisi->depth = $depth; |
|
|
|
array_push($array, $divisi); |
|
|
|
array_push($array, $divisi); |
|
|
|
foreach ($divisi->children as $child) { |
|
|
|
foreach ($divisi->children as $child) { |
|
|
@ -17,9 +18,10 @@ class DivisiController extends Controller |
|
|
|
return $array; |
|
|
|
return $array; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function add(Request $request){ |
|
|
|
public function add(Request $request) |
|
|
|
|
|
|
|
{ |
|
|
|
$this->validate($request, [ |
|
|
|
$this->validate($request, [ |
|
|
|
'name' => 'string|required|unique:m_divisi,name', |
|
|
|
'name' => 'string|required|unique:m_divisi,name,NULL,id,company_id,' . $request->input('company_id'), |
|
|
|
'description' => 'nullable|string', |
|
|
|
'description' => 'nullable|string', |
|
|
|
'parent' => 'nullable|integer', |
|
|
|
'parent' => 'nullable|integer', |
|
|
|
'color' => 'nullable|string|max:10' |
|
|
|
'color' => 'nullable|string|max:10' |
|
|
@ -36,7 +38,8 @@ class DivisiController extends Controller |
|
|
|
return response()->json(['status' => 'success', 'message' => 'Data created!', 'code' => 200]); |
|
|
|
return response()->json(['status' => 'success', 'message' => 'Data created!', 'code' => 200]); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function update(Request $request, $id){ |
|
|
|
public function update(Request $request, $id) |
|
|
|
|
|
|
|
{ |
|
|
|
if (empty($id) || !is_int((int)$id)) |
|
|
|
if (empty($id) || !is_int((int)$id)) |
|
|
|
return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); |
|
|
|
return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); |
|
|
|
|
|
|
|
|
|
|
|