Row count and sum in laravel

Friends, in today’s tutorial we will learn aggregate functions. Aggregate functions means that we will run sum operation, average operation, count operation inside our database, overall I would say a mathematical operation inside it.

Let us explain to you how aggregate functions are used in Laravel:

$count = DB::table('is_profile_completed')->where('userd', $userid)->count();
$sum = DB::table('is_profile_completed')->where('userd', $userid)->sum('salary');

$data = DB::table('posts')->where('post_status_for_frontend', 1)->orderBy('updated_at', 'desc')->paginate(4);
{{count($data)}}

 

 

Leave a Reply