|
|
|
@ -8,7 +8,8 @@ use App\Models\Divisi;
|
|
|
|
|
class DivisiController extends Controller |
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
private function getAllChildren($divisi, $depth = 0, $array = []) { |
|
|
|
|
private function getAllChildren($divisi, $depth = 0, $array = []) |
|
|
|
|
{ |
|
|
|
|
$divisi->depth = $depth; |
|
|
|
|
array_push($array, $divisi); |
|
|
|
|
foreach ($divisi->children as $child) { |
|
|
|
@ -17,9 +18,10 @@ class DivisiController extends Controller
|
|
|
|
|
return $array; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function add(Request $request){ |
|
|
|
|
public function add(Request $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', |
|
|
|
|
'parent' => 'nullable|integer', |
|
|
|
|
'color' => 'nullable|string|max:10' |
|
|
|
@ -36,7 +38,8 @@ class DivisiController extends Controller
|
|
|
|
|
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)) |
|
|
|
|
return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); |
|
|
|
|
|
|
|
|
|