Where are you setting that, and how? if your using pluck tags, you can set true which will only find unique tags, and i think in turn, will mean you wont end up with duplicate article images.
But there are bits of your code that doesnt make alot of sense. your setting $existing = ''; and then using it while empty inside ->not(), which wont do anything.
Then $existing .= '\'' . $selectedArticle . '\', '; … what are you trying to do there? you don’t seem to be using these variables in the rest of the foreach, apart from $image
No, that’s not quite correct, because if each article has multiple tags, it could happen that you get duplicated images.
@iam_timm Your general idea is correct, but you would have to add the newly found article to a new pages collection (at least that makes things easier) that you declare outside the loop (otherwise, it will be empty again at each new loop). Also, your selected article is not a single page but a collection, so using findBy() is more useful here, or limit filterBy() to the first article.
However, what if you are left without an article for the tag, because the one with only one tag was already used for another tag?