Laravel db raw with sum of column example

December 27, 2017 | Category : Laravel PHP

I will let you know how to use mysql sum function with select statement in laravel 5. we will use db raw with sum function in laravel. In this article i will leave simple example of laravel select sum group by with db::raw.

If you require to use sql sum() in select statement then you are a right place. If you have to write simple sql query then it is a very simple to write but if you need to use mysql predefine function then you require to use sum() using db raw.

So, basically bellow query i want to count number of address of per user, So let's see how will bellow query.


$data = DB::table("users")

->select(DB::raw("SUM( as total_address"))





I hope you understand and found your best solution....