Can you put the foreach attachments inside the if condition? There’s no need to loop if attachment is empty