mardi 9 octobre 2018

Select top from group

I have model Message:

 protected $fillable = [
        'id','text','girl_id','date' ];

How to choose the last message by date for each girl_id?

My code:

   $messages=Message::select(['id','text','girl_id','date'])
                    ->groupBY('girl_id')
                    ->orderBY('date')
                    ->take(1)
                    ->get();



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire