lundi 14 octobre 2019

How to select distinct records ordered by date column desc - Laravel

I have such table:

app_id | releaseDate 
111  | 2019-04-21
111  | 2019-05-10
222  | 2019-07-21
222  | 2019-04-22
222  | 2019-05-25
333  | 2019-06-21
333  | 2019-05-21

I need to get such result (need to order desc by releaseDate and after select distinct):

111 | 2019-05-10
222 | 2019-07-21
333 | 2019-06-21

My code:

$apps_histories = ApplicationHistory::with('application')->whereBetween('releaseDate', ['2014-10-01', '2019-10-14'])
            ->orderBy('releaseDate', 'DESC')
            ->groupBy('app_id')
            ->get();

I got:

111 | 2019-04-21
222 | 2019-04-22
333 | 2019-05-21

I have tried different approaches, but I don't get why it's not working as I expect. Could you please help?



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

Aucun commentaire:

Enregistrer un commentaire