mercredi 4 avril 2018

Laravel 5.4 Eloqent relationship query return null using ->first()

I hope anybody can help me with this.

I have the next eloquent query:

$chats = Solicitud::with(['reservation', 'detail.subDetails', 'conversation'=>function($q){
                     $q->orderBy('created_at', 'DESC')->groupBy('solicitud')->first();
                }])
                    ->whereIn('idSolicitud', $r)
                    ->skip($inicio)
                    ->take($elementos)
                    ->orderByRaw("field(idSolicitud, ".implode(',' , $r->toArray()).")")
                    ->get();

What I want is get the last conversation so I use ->first() to get the last. But this return conversation:[] without data, but when I change ->first() to ->get() return all the conversation I don't know what is wrong.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire