lundi 4 février 2019

Laravel: Query with where clause gone wrong

What I am trying to achieve is to allow teachers to import a student into different classes. Note: A student can be multiple classes.

The problem is that when I show the list of students in a select dropdown it should return all students except for students that are not in this class (the class being the page that I am on, app.com/classes/5 for example).

$students = User::join('group_user', 'users.id', '=', 'group_user.user_id')->role('student')->where('group_user.group_id', '!=', $id)->orderBy('users.name', 'asc')->get();

This works and shows all students that are not in this specific class BUT if a student that's in this class and another class their name appears in the list and as duplicate names.

What can I do?



from Newest questions tagged laravel-5 - Stack Overflow http://bit.ly/2WG1Ad0
via IFTTT

Aucun commentaire:

Enregistrer un commentaire