/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, $id) { $validator = Validator::make($request->all(), ['nama' => 'required|unique:bahagian,nama|max:255'], ['nama.required' => 'Nama bahagian adalah diperlukan', 'nama.unique' => 'Nama bahagian pernah didaftarkan didalam sistem', 'nama.max' => 'Nama bahagian tidak boleh panjang daripada 255 aksara']); if ($validator->fails()) { return ['success' => false, 'message' => $validator->errors(), 'populate' => $request->all()]; } else { $bahagian = Bahagian::findOrFail($id); $bahagian->nama = $request->get('nama'); $bahagian->aktif = 1; if ($request->has('bahagian_id') && !$request->get('induk')) { $bahagian->bahagian_id = $request->get('bahagian_id'); } $bahagian->save(); return ['success' => true]; } }