user(); return response()->json(['profile' => [ 'name' => (string) $user->name, 'email' => (string) $user->email, 'is_super_admin' => method_exists($user, 'isManagerSuperAdmin') && $user->isManagerSuperAdmin(), 'groups' => method_exists($user, 'managerGroups') ? $user->managerGroups()->pluck('name')->values() : [], 'theme' => $themes->keyFor($user), 'themes' => config('manager.user_themes') ? collect($themes->all())->map(fn (array $theme, string $key) => ['key' => $key, 'label' => $theme['label'], 'colors' => $theme['colors']])->values() : [], ]]); } public function update(Request $request, Themes $themes): JsonResponse { $user = $request->user(); app(AuditTrail::class)->about($user); $data = $request->validate([ 'name' => ['required', 'string', 'max:255'], 'current_password' => ['nullable', 'string', 'max:200'], 'password' => ['nullable', 'string', 'min:12', 'max:200', 'confirmed'], 'theme' => ['nullable', 'string', Rule::in(array_keys($themes->all()))], ]); if (($data['password'] ?? '') !== '' && ! Hash::check((string) ($data['current_password'] ?? ''), $user->getAuthPassword())) { return response()->json(['message' => 'The current password is not right.', 'errors' => ['current_password' => ['The current password is not right.']]], 422); } $user->name = $data['name']; ($data['password'] ?? '') !== '' && $user->password = Hash::make($data['password']); $user->save(); if (config('manager.user_themes') && $request->has('theme')) { UserSetting::query()->updateOrCreate(['user_id' => $user->getKey()], ['theme' => $data['theme'] ?: null]); } return response()->json(['saved' => true]); } }