user()->village->district->city->province->code)->get(); $districts = District::where('city_code', auth()->user()->village->district->city->code)->get(); $villages = Village::where('district_code', auth()->user()->village->district->code)->get(); return view('profile.index', compact('provinces', 'cities', 'districts', 'villages')); } public function updateProfile(Request $request) { $nama_depan = str_replace(' ', '_', $request->nama_depan); $nama_belakang = str_replace(' ', '_', $request->nama_belakang); $nohp = $request->nohp; $kode_kelurahan = $request->kelurahan; $alamat = $request->alamat; $nama_bank = $request->nama_bank; $no_rek = $request->no_rek; $foto_profile = ''; if ($request->hasFile('foto')) { $file = $request->file('foto'); $foto_profile = 'Foto_Profil_' . $nama_depan . '_' . $nama_belakang .'.'. $file->getClientOriginalExtension(); $path = 'foto-profile/' . $foto_profile; Storage::disk('public')->put($path, file_get_contents($file)); } try { DB::beginTransaction(); User::where('id', Auth::user()->id)->update([ 'nama_depan' => $nama_depan, 'nama_belakang' => $nama_belakang, 'nohp' => $nohp, 'kode_kelurahan' => $kode_kelurahan, 'alamat' => $alamat, 'nama_bank' => $nama_bank, 'no_rek' => $no_rek, 'foto_profile' => $foto_profile, ]); DB::commit(); return response()->json(['status' => true, 'message' => 'Data Profile berhasil diupdate']); } catch (Throwable $e) { DB::rollBack(); Log::error($e->getMessage()); return response()->json(['status' => false, 'message' => 'Terjadi Kesalahan pada sisi server']); } } public function changePassword(Request $request){ $currentPassword = $request->currentPassword; $newPassword = $request->newPassword; $renewPassword = $request->renewPassword; if(!Hash::check($currentPassword, auth()->user()->password)){ return response()->json(['status' => false, 'message' => 'Password sekarang tidak sama','password' => $currentPassword]); } if($renewPassword != $newPassword){ return response()->json(['status' => false, 'message' => 'Ketikan ulang password baru']); } try{ DB::beginTransaction(); User::where('id', auth()->user()->id)->update([ 'password' => Hash::make($newPassword) ]); DB::commit(); return response()->json(['status' => true, 'message' => 'Password Berhasil diubah']); }catch(Throwable $e){ DB::rollBack(); Log::error($e->getMessage()); return response()->json(['status' => false, 'message' => 'Terjadi Kesalahan pada sisi server']); } } }