$results = User::select(\DB::raw('YEAR(date) as year, COUNT(id) as amount'))
->groupBy(\DB::raw('YEAR(date)'))
->get();
So, we’re using DB::raw() for all select statement, also repeating the same condition in groupBy(). Here’s the visual result for my dummy seeded data: