A Laravel app has a users table and a roles table with a many-to-many relationship. A query for all admins is returning duplicate users. What is the Eloquent fix?
-
A
Add ->distinct() or use whereHas('roles', fn($q) => $q->where('name', 'admin')) instead of a JOIN
-
B
Add a UNIQUE constraint to the pivot table's user_id column
-
C
Use groupBy('users.id') in raw SQL
-
D
Delete duplicate rows from the role_user pivot table