lundi 27 mars 2017

laravel groupby with orderby

    DB::table('group_lists')
        ->join('conversationsV2', 'group_lists.conversationsV2_id', '=', 'conversationsV2.id')
        ->join('messagesV2', 'group_lists.conversationsV2_id', '=', 'messagesV2.conversationsV2_id')
        ->whereIn('group_lists.conversationsV2_id', function ($query) use ($userID) {
            $query->select('conversationsV2_id')->from('group_lists')
                ->where('user_id', $userID)->get();
        })
        ->select('group_lists.user_id', 'conversationsV2.id', 'conversationsV2.type',
            DB::raw('max(messagesV2.id) as mid')
            , 'group_lists.conversationsV2_id')
        ->where('group_lists.user_id', '!=', $userID)
        ->groupBy('messagesV2.conversationsV2_id')
        ->orderBy('messagesV2.id', 'DESC')
        ->get();

MessageV2

Messagev2

grouplist enter image description here

Conversationv2 enter image description here

the Line ->orderBy('messagesV2.id', 'DESC') is not working due to ->groupBy('messagesV2.conversationsV2_id') so there any way i can groupby and orderby at the same time



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2mJPjpA
via IFTTT

Aucun commentaire:

Enregistrer un commentaire