Vilfago7 years agoLevel 20ReplyReport SpamIf you want it processed by the db, you should create a custom query using sum : https://laravel.com/docs/5.7/queries#aggregates Or you can retrieve employee information using with, and then sum the item in collection :https://laravel.com/docs/5.7/collections#method-sum Like Reply
staudenmeir7 years ago Best Answer Level 24ReplyReport SpamUse this: $depts = Department::withCount([ 'employees as salaries' => function($query) { $query->select(DB::raw('sum(salary)')); } ])->get(); Like Reply