php - How to use "where not" in a Laravel Model Relationship? -
i have user table similar to: === users === id: int (pk) name: string is_coach: bool ... and coach request table similar to: === coach_requests === id: int (pk) student_id: int(fk => users.id) coach_id: int(fk => users.id) ... i have corresponding laravel models (i.e. user , coachrequest ). in user model, wish make method such given specified user, return users is_coach = true , except: him/herself , users have been matched person coach in coach_requests table. for example consider following sample data: users (1, "a", false) (2, "b", true) (3, "c", true) (4, "d", true) (5, "e", true) (6, "f", true) coach_requests (1, 2, 3) (2, 2, 4) (3, 3, 2) (4, 3, 6) (5, 4, 5) (6, 4, 6) (7, 5, 6) (8, 6, 5) (9, 1, 4) now if user with: id 1 (i.e. user "a"), return user ids: 2, 3, 5 , 6 id 2, return user ids: 5, 6 id 3, return user ids: 4, 5 id 4, return user ids: 2, 3 id 5, return user ...