input('month', Carbon::now()->format('Y-m')); $user = Auth::user(); $administrations = $this->userService->getDashboard($user, $selectedMonth); $stats = $this->userService->getPersonalStats($user, $selectedMonth); $receivedRanking = $this->userService->getRankingList('received', $selectedMonth, $user); $sentRanking = $this->userService->getRankingList('sent', $selectedMonth, $user); return view('user.dashboard', array_merge([ 'administrations' => $administrations, 'selectedMonth' => $selectedMonth, 'user' => $user, 'receivedRankers' => $receivedRanking['rankers'], 'receivedCurrentUserRankItem' => $receivedRanking['currentUserRankItem'], 'sentRankers' => $sentRanking['rankers'], 'sentCurrentUserRankItem' => $sentRanking['currentUserRankItem'] ], $stats)); } public function sendThankcards() { $users = $this->userService->getOtherActiveUsers(Auth::user()); return view('user.send', compact('users')); } public function storeThankcards(Request $request) { $request->validate([ 'receiver' => [ 'required', \Illuminate\Validation\Rule::exists('user', 'msnv')->where('status', config('constants.STATUS_ACTIVE')) ], 'amount' => 'required|integer|min:1|max:' . Administration::MAX_SEND_CARD_PER_MONTH, ]); try { $this->userService->sendThankcards( Auth::user(), $request->receiver, (int) $request->amount ); } catch (\RuntimeException $e) { return response()->json(['success' => false, 'message' => $e->getMessage()], 422); } return response()->json(['success' => true, 'message' => __('messages.thank_card_send_success')]); } public function changePasswordForm() { return view('user.change_password'); } // Show edit profile page (avatar & password) public function editProfile() { return view('user.edit'); } // Handle avatar upload and optional password change public function updateProfile(Request $request) { $request->validate([ 'avatar' => 'nullable|image|max:2048', // 2MB max 'new_password' => 'nullable|min:6|confirmed', ]); $user = Auth::user(); // Avatar handling if ($request->hasFile('avatar')) { $path = $request->file('avatar')->store('avatars', 'public'); $user->avatar = 'storage/' . $path; } // Password handling (optional) if ($request->filled('new_password')) { $this->userService->updatePassword($user, $request->new_password); } $user->save(); return redirect()->route('user.edit')->with('success', 'Cập nhật hồ sơ thành công'); } }