Check out example codes for "sql select sum group by id laravel join". It will help you in understanding the concepts better.

Code Example 1

$users = User::select('users*', 'analytics.*', DB::raw('SUM(analytics.revenue) As revenue'))
         ->leftJoin('analytics', 'analytics.user_id', '=', 'users.id')
         ->where('analytics.date', Carbon::today()->toDateString())
         ->get();

Learn ReactJs, React Native from akashmittal.com