json([ 'data' => $this->preferences($request), ]); } public function update(UpdateNotificationPreferencesRequest $request): JsonResponse { $user = $request->user(); $validated = $request->validated(); $user->forceFill([ 'social_notifications_enabled' => $validated['socialNotificationsEnabled'] ?? $user->social_notifications_enabled, 'engagement_reminders_enabled' => $validated['engagementRemindersEnabled'] ?? $user->engagement_reminders_enabled, ])->save(); return response()->json([ 'data' => $this->preferences($request), 'code' => 'NOTIFICATION_PREFERENCES_UPDATED', ]); } /** @return array{socialNotificationsEnabled: bool, engagementRemindersEnabled: bool} */ private function preferences(Request $request): array { return [ 'socialNotificationsEnabled' => (bool) $request->user()->social_notifications_enabled, 'engagementRemindersEnabled' => (bool) $request->user()->engagement_reminders_enabled, ]; } }