Skip to content
Advertisement

How to count the rows by created date in Laravel query builder?

I am trying to count the rows by created_at like

Created_at                        COUNT(*)
----------------------------------- ----------
2017-08-13                                    5
2017-08-12                                    6
2017-08-11                                    7
2017-07-10                                    8
2017-07-19                                    1

So I can show the client like in 2017-07-10, there are 8 people signed up. In 2017-08-13, there are 5 people signed up or something like that.

Here is what I tried,

$count=DB::table('jobseekers')->select('created_at')->groupBy('created_at')->count();
    // return $count;
    dd($count);

but this is just showing only the number.

Advertisement

Answer

You could try something like this:

$count = DB::table('jobseekers')
             ->select('created_at', DB::raw('count(*) as peoples'))
             ->groupBy('created_at')
             ->get();
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement