email)->firstOrNew(); if ($request->optin) { if (CustomerInfo::getFromEmail($service->brand, $request->email)->where('opt_in', true)->exists()) { throw new ApiErrorException(ApiError::singleOptinCustomerExists()); } $singleOptin->fill($request->validated()); $singleOptin->brand()->associate($service->brand); $singleOptin->saveOrFail(); } else { $singleOptin->delete(); } return response()->json(); } }