jeudi 12 octobre 2017

How to get first record of each group created using groupBy() with Laravel eloquent model?

I have a table structured as following named renewals.

------------------------------------------------
| id  | membership_id| valid_from | valid_upto |
------------------------------------------------
|  1  | 1            | 2015-02-15 | 2016-02-15 |
|  2  | 2            | 2015-05-16 | 2016-05-16 |
|  3  | 2            | 2016-05-16 | 2017-05-16 |
|  4  | 3            | 2014-06-16 | 2015-06-16 |
|  5  | 3            | 2015-06-16 | 2016-06-16 |
|  6  | 3            | 2016-06-16 | 2017-06-16 |
|  7  | 1            | 2016-02-15 | 2017-02-15 |
------------------------------------------------

I need to get record of each members with latest valid_upto date. How to do that using Laravel Eloquent. Any other easy method will be appreciated.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire