all(), [ 'uuid' => 'required|string|exists:applications,uuid', 'domains' => 'required|array', 'domains.*' => 'required|string|distinct', ]); if ($validator->fails()) { return response()->json([ 'success' => false, 'message' => 'Validation failed', 'errors' => $validator->errors(), ], 422); } $application = Application::where('uuid', $request->uuid)->first(); if (! $application) { return response()->json([ 'success' => false, 'message' => 'Application not found', ], 404); } $existingDomains = explode(',', $application->fqdn); $domainsToDelete = $request->domains; $updatedDomains = array_diff($existingDomains, $domainsToDelete); $application->fqdn = implode(',', $updatedDomains); $application->custom_labels = base64_encode(implode("\n ", generateLabelsApplication($application))); $application->save(); return response()->json([ 'success' => true, 'message' => 'Domains updated successfully', 'application' => $application, ]); } }