create toggleEmailNotifications method in user controller

This commit is contained in:
2026-03-26 09:13:57 +01:00
parent c1d7f5cd81
commit 712bdd02cd
+14
View File
@@ -350,4 +350,18 @@ class UserController extends Controller
return response()->json(['message' => "Server error"], 500);
}
}
public function toggleEmailNotifications(Request $request, int $id): JsonResponse {
try {
$user = User::findOrFail($id);
$user->email_notifications = !$user->email_notifications ? 0 : 1;
$user->save();
return response()->json($user);
}catch(\Exception $e){
Log::info($e->getMessage());
return response()->json(['message' => "Server error"], 500);
}
}
}