Laravel Eloquent get results grouped by days

前端 未结 14 654
一整个雨季
一整个雨季 2020-12-02 06:44

I currently have a table of page_views that records one row for each time a visitor accesses a page, recording the user\'s ip/id and the id of the page itself. I should add

14条回答
  •  醉酒成梦
    2020-12-02 07:31

    I built a laravel package for making statistics : https://github.com/Ifnot/statistics

    It is based on eloquent, carbon and indicators so it is really easy to use. It may be usefull for extracting date grouped indicators.

    $statistics = Statistics::of(MyModel::query());
    
    $statistics->date('validated_at');
    
    $statistics->interval(Interval::$DAILY, Carbon::createFromFormat('Y-m-d', '2016-01-01'), Carbon::now())
    
    $statistics->indicator('total', function($row) {
        return $row->counter;
    });
    
    $data = $statistics->make();
    
    echo $data['2016-01-01']->total;
    

    ```

提交回复
热议问题