Q:

Sql querying by the day displays different results

I want to query records by day in a table count them and group by the day but it doesn't display correct data
$VisitsTrends=DB::table('visits')
            ->select('created_at',\DB::raw('count(*) as total'))
            -> groupBy('created_at')->get();
          dd($VisitsTrends);

it just displays data by each time and counts differently

A:

You may use
use Illuminate\Support\Facades\DB;
//...
$VisitsTrends = Visit::groupBy('date')->get(array(
      DB::raw('Date(created_at) as date'),
      DB::raw('COUNT(*) as "total"')
));

