This query is for getting other data with the highest value of date with the group by/unique. Here I used unique in place of group by.  

My question is how to get min(date) and max(date) with group by/unique.
The group by/unique is for Dataset table's date field.  

I have searched for this but not getting exact solution that how to get max and min date with group by/unique in laravel eloquent.  

In table structure, there are multiple entries for one code so here I used group by/unique to get one record for the code.

There can be multiple dates as 02-01-2003,01-03-2007,01-01-2019, 01-07-2018... etc. with same/ different code. If I group by with code then get onmy one record per code. So here I want to select the max date [01-01-2019] and min date [02-01-2003].

Thanks in advance.

Controller:

```
$datasets = Dataset::where('user_id', $user_id)
          ->orderBy('date','desc')
          ->get(['code', 'access','user_id','date'])
          ->unique('code');

```