To select specific columns in laravel by select by obligation you must bring the id and the fk so that the tuples can be related, but when I want to do a - > select () between a much relation a lot does not work for me since in the middle there is a pivot table and I guess that you should still load your pk and fk. as is usually done in relations of other cardinalities.
How should I put the fk and pk of the pivot table in the select to bring specific fields?
Suppose we have a notification that is related to many-to-many users, and that notification may have N comments related to a notification (a notification may have N comments, a comment may only be in a notification)
for example
$comentarios = Comentario::select('id','texto','users_fk','notificaciones_fk','created_at','updated_at')
->where('notificaciones_fk', $request->notificacion_id)
->where('activo', 1)
->orderBy('id','DESC')
->with(['notificacion.users' => function($query){
$query->with('perfil');
// En este $query aplicar un select para traer campos específicos de usuarios,
// pero al haber una tabla pivote de por medio, como debo especificar la id y las fk
// de la tabla pivote? Independientemente de que utilice select() o
// cargue con eager loading los atributos :id,atributo,atributo_fk debo
// especificar los primary y foreign para que se pueda llevar a cabo la
// consulta
}])
->paginate($perPage);
Or failing that, is there a way to remove or hide columns from queries other than adding fields in the $ hidden property of the model?