I'm looking for the cleanest way to do this. I have three tables: users, user_identifiers, and bans. bans and user_identifiers have foreign keys that reference a user. The user_identifiers table has an identifier_type column as well as a data column to differentiate between different types of identifiers. Each user has several identifiers.
I'm trying to figure out the best way to pull all of the identifiers of a particular user and check to see if they have any duplicate identifiers with other users (keeping in mind that data and type matters). If there are duplicate identifiers, I want to check to see if any of the users with matching identifiers are banned. If so, then I want to ban the current user.
I'd like to be able to do this completely using eloquent if possible and with minimal looping to optimize performance.