Personally, I’ve never had any problems collecting miles I was eligible for when booking directly with the airline (e.g. Lufthansa, Austrian, United, etc).
My guess is that the flights the OP booked directly were in fare classes not eligible for mileage accrual, while the flights booked with OTAs were. Thus, this issue is actually not at all about the ease of collecting miles when booking directly vs. booking through an OTA.