Laravel eloquent relation ship empty using select

My code

$users = Classroom::with(['students.classrooms',
                          'students' => function ($query) use ($search, $validated, $user) {
                              $query->select('name', 
                                             'firstname', 
                                              'email', 
                                              'nickname', 
                                              'locale', 
                                              'timezone', 
                                              'classroom_user.created_at', 
                                              'avatar', 
                                              'lastConnection', 
                                              'level', 
                                              'level_ja', 
                                              'classroom_user.classroom_id', 
                                              'classroom_user.user_id',
                                             );                                                         
                    },
                ])
                    ->whereIn('id', $classroom_ids)
                    ->get()
                    ->pluck('students')
                    ->flatten();

                $users = $users->paginate(10);

Using the select method on "students" relation make "classrooms" empty in the result, but if I don't use the select method, classrooms is not empty.

My question

How to add students.classrooms relation in the select method in "students" relation?



from Recent Questions - Stack Overflow https://ift.tt/2USOq0h
https://ift.tt/eA8V8J

Comments

Popular posts from this blog

Today Walkin 14th-Sept

Spring Elasticsearch Operations

Hibernate Search - Elasticsearch with JSON manipulation